Master listing of CPP symbols

Guido van Rossum guido at mcvax.UUCP
Tue Oct 16 08:49:25 AEST 1984


Now that's the second compilation of predefined CPP symbols coming around
this month.  These symbols almost all seem to indicate particular hardware
or software a program might be running on (exception: __FILE__ c.s.).

I can't believe there is any program which checks for more than three
or four of them (counterexamples to /dev/null, please).  I suspect most
people use them in a fashion like

	#ifdef MY_MACHINE
		... Do some local tricks ...
	#endif

or

	#ifndef MACHINE_X
		... This doesn't work on machine X ...
	#endif

or

	#ifdef SYSTEM_X
		... Way to do it on sys X ...
	#else
		... Way to do it somewhere else ...
	#endif

Of course, this breaks when a program is spread to more that a few machines.
What we really need here is something quite different: a set of #defines
telling us what *features* are available on the target machine.  (Note
that the machine where the compiler runs is immaterial, unless it is
a very buggy compiler.)  So:

	#ifdef ETHERNET
		... Collect and display info about net nodes ...
	#endif

and

	#ifdef SELECT_SYSCALL
		... Find out whether there's input pending ...
	#else
		... Assume there is (or isn't) ...
	#endif

I feel that, in the end, this is much more portable than using system
names, where it will always be possible that a new system Z is a mixture
of system X and system Y, thus necessitating a new #define although all
the features are really nothing new.  (I believe this is in fact already
the case for many of the systems on the circulated lists.)

(Aside: I've always wondered what use there was for Decus' "nomacargs".
Either you can do the job without macro arguments; then do so, and
you won't have to bother; or you can't, and then you're pretty helpless
anyway when faced with the Decus compiler.  But I shouldn't complain
too loud, as it follows my proposal: #ifdef nomacargs is better than
#ifdef DECUS.)

Random shots at related topics:
	- #defined symbols should usually be recognizable by a convention
	  line all uppercase (exception: getchar and such that must look
	  like functions);
	- *pre*defined symbols should stand out even more because they
	  may be there without the user knowing about them; perhaps __LINE__
	  and __FILE__ might set a standard (or the ANSI committee? :-)
	- it's nice if the ANSI standard finds a way out which makes
	  things like 'unix' be defined and still evaluate to 'unix'
	  by explicitly ruling out recursion; but have they thought about
	  mutual recursion (#define a b; #define b a)?
	- I feel that "unix is on my side": during some stage of the
	  development of the unix kernel, tests like #ifdef pdp111
	  were replaced by #ifdef UNIBUS etc.

--
	Guido van Rossum, "Stamp Out BASIC" Committee, CWI, Amsterdam
	guido at mcvax.UUCP

"What was your mandoline doing in my bed?"



More information about the Comp.lang.c mailing list