Can #define `token-string' be empty?

Ray Lubinsky rwl at uvacs.UUCP
Mon Feb 25 05:39:59 AEST 1985


> > Is
> > 	#define	X
> > valid, i.e., can the `token-string' mentioned on page 207 of K&R be empty?
> 
> Yes.  the default value of X is 1.
> 
> 					larry...

   This is also the way I've understood #define, but I made a little program
just to test it out.  Fact is, X is not literally given a default value of 1.
You can really only say that it has the value of "defined" as far as the
pre-processor (/lib/cpp) is concerned.  Consider the following C program which
I fed to /lib/cpp :

C source:				Output from preprocessor:
===================================	=======================================
#include <stdio.h>			...  (stuff from the include file here)
#define	X

main()					main()
{					{
	printf("This is X: %d\n",X);		printf("This is X: %d\n",);
}					}

   Clearly, X was not considered to be 1 (or anything), and when I attempted to
used the test  #if X == 1  , the preprocessor complained of syntax error (since
it translated the line into  #if  == 1  .

   Empty #define's should be used only in connection with #ifdef and #ifndef
tests.  Otherwise they have little usefulness.

------------------------------------------------------------------------------

Ray Lubinsky		     University of Virginia, Dept. of Computer Science
			     uucp: decvax!mcnc!ncsu!uvacs!rwl

--------------  The mind is buddha.  The mind is not buddha.  ----------------



More information about the Comp.lang.c mailing list