C preprocessor question

Chris Torek chris at mimsy.UUCP
Mon Feb 2 12:03:15 AEST 1987


The example was:

>>#define GROUP(group,subgroup) (((group) << 8) | (subgroup))
>>#if GROUP(0,0)
>>#endif

In article <4136 at brl-adm.ARPA> moss at BRL.ARPA (Gary S. Moss (SLCBR-VLD-V))
writes:
>The pre-processor defined macros are not evaluated by CPP.

Some are; others are confused.

>In other words, "#if GROUP(0,0)" is illegal because GROUP(0,0) has no value.

Yet

	#define GROUP 1
	#if GROUP
	...
	#endif

is legal, and works.

The 4.3BSD cpp gets very confused when handed

	#define I(a) a
	#if I(1)
	gorp
	#endif

Compiling this with `cc -E' produces

	# 1 "xx.c"

	xx.c: 4: syntax error
	 1
	gorp
	#endif
	xx.c: 5: missing endif

which is hardly proper behaviour.  If parameterised macros are not
to be evaluated, this should be either a syntax error (`#if
<unparseable>') or a false conditional (`#if <undefined>' is now
treated as is `#if 0').  If they are to be evaluated, this should
be equivalent to `#if 1', and the original example should have
worked too.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list