Pretty please: no more lower-case macros !!!

Simon 'corecode' Schubert corecode at fs.ei.tum.de
Thu Jan 6 01:35:51 PST 2005


On Thursday, 6. January 2005 10:00, Adrian Bocaniciu wrote:
>  As I have already mentioned in a follow-up to my recent bug report, the
> essential ports net/quagga and net/zebra have been totally broken by the
> use of lower-case macros in the DragonFly system headers.
>
>  There is an old C tradition that the identifiers used in macro
> definitions must be written entirely with capital letters and that no
> other identifiers should be written like that.  This tradition has not
> been caused by esthetic reasons but by the need to separate the name
> spaces for macros and for other identifiers.

I think you are mistaking something here. Macros are traditionally written 
upper case if they evaluate their arguments more than one time, iirc.

If you want to be portable, #define POSIX_SOURCE or what it is called and 
don't include sys/* files. These lower case macros are usually for 
convenience or compatibility.

For example <netdb.h>:

struct  hostent {
        char    *h_name;        /* official name of host */
        char    **h_aliases;    /* alias list */
        int     h_addrtype;     /* host address type */
        int     h_length;       /* length of address */
        char    **h_addr_list;  /* list of addresses from name server */
#define h_addr  h_addr_list[0]  /* address, for backward compatibility */
};

as you can see, it's an often used compatibility define. and those are usually 
prefixed with an acronym from the struct (h_). Unfortunately, conflicts 
happen, but you can't avoid it. Removing those defines would result in a much 
larger breakage, I'd guess.

>  In the case of net/route.h, where I first encountered such macros, they
> were used to provide alternate names for some structure members.  That
> can be done in a perfectly safe way without macros, by using anonymous
> unions.  Even if, for some very stupid reason (as the named unions were
> really a mistake in the original C design) the anonymous unions have not
> made their way yet into the official C standard, gcc and most other C
> compilers support anonymous unions also in C, not only in C++.

I'm not sure if this will always work. Could you give an example which will 
compile with gcc2 and gcc34 without warnings?

cheers
  simon

-- 
/"\
\ /
 \     ASCII Ribbon Campaign
/ \  Against HTML Mail and News
Attachment:
pgp00001.pgp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00001.pgp
Type: application/octet-stream
Size: 187 bytes
Desc: "Description: PGP signature"
URL: <http://lists.dragonflybsd.org/pipermail/bugs/attachments/20050106/3e7e65bb/attachment-0016.obj>


More information about the Bugs mailing list