[net.unix-wizards] Bad choice of preprocessor variable name

phil@RICE.ARPA (William LeFebvre) (07/09/85)

I really like the idea of predefined preprocessor names that identify
the architecture/os of the host, such as:  sun, vax, vax11c, etc....
But I just ran into a major, major problem.  Whoever decided that these
names should be lower case should be shot!

Consider the 4.2 networking code.  The common name to use for a "struct
sockaddr_in" (a structure that defines an Internet domain socket) is
"sin".  Look at the 4.2 IPC Primer.  Now, consider what the common name
would be for a Unix domain socket, or, more specifically, a "struct
sockaddr_un".  You guessed it:  "sun".

Aww, geez.  Now who would be THAT stupid, hmmmm???  Look at the source
for the 4.2 line printer spooling software, specifically: "lpd.c" and
"startdaemon.c" (the latter is used by "lpc").  Guess what?!?  "struct
sockaddr_un sun;"  Now try compiling that on a Sun!  It don't work too
well.

Why not "Sun" and "Vax" (or, better yet, "VAX")?  What ever happened to
putting all preprocessor names in upper case?

			William LeFebvre
			Department of Computer Science
			Rice University
			<phil@Rice.arpa>
                        or, for the daring: <phil@Rice.edu>

dick@tjalk.UUCP (Dick Grune) (07/11/85)

In article <11428@brl-tgr.ARPA> phil@RICE.ARPA (William LeFebvre) writes:
>I really like the idea of predefined preprocessor names that identify
>the architecture/os of the host, such as:  sun, vax, vax11c, etc....

> ... these may coincide with variable names ... [summary by dick@tjalk.UUCP]

>     .....                                      Guess what?!?  "struct
>sockaddr_un sun;"  Now try compiling that on a Sun!  It don't work too
>well.

You can have your cake and eat it: the new Amsterdam Compiler Kit C compiler
would have sun defined and replace it by sun.

					Dick Grune
					Vrije Universiteit
					de Boelelaan 1081
					1081 HV  Amsterdam
					the Netherlands

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (07/14/85)

> You can have your cake and eat it: the new Amsterdam Compiler Kit C compiler
> would have sun defined and replace it by sun.

But this approach does not work with the large amount of existing code
that contains things like

#if u370 || pdp11

instead of

#if defined(u370) || defined(pdp11)

And in any case, it breaks

#define	sun( x )	(some-expression)

I don't think this problem has any really good solution.
ANSI C would forbid predefined things like this.