Can #define `token-string' be empty?

Tim Maroney tim at cmu-cs-k.ARPA
Fri Feb 22 05:42:07 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...

Wrong.  The default value of X is nothing.  Any instances of the token X
will be removed from the source file before parsing.  This is frequently
used to make include files do double duty.  At the start of the include
file, put

#ifndef EXTERN
#define EXTERN extern
#endif

Then the include file should contain declaratons of this form:

EXTERN int global_int;
EXTERN struct marsupial *wombat;

Including the file normally causes these to be external declarations, that
is, no space is allocated for the variables.  Then, in the source file where
you want to actually have the variables' storage allocated, you just say

#define EXTERN
#include "whatever.h"
-=-
Tim Maroney, Carnegie-Mellon University Computation Center
ARPA:	Tim.Maroney at CMU-CS-K	uucp:	seismo!cmu-cs-k!tim
CompuServe:	74176,1360	audio:	shout "Hey, Tim!"

"Remember all ye that existence is pure joy; that all the sorrows are
but as shadows; they pass & are done; but there is that which remains."
Liber AL, II:9.



More information about the Comp.lang.c mailing list