Is it only ANSI C that allow #if to compare symbols?

Norman Diamond diamond at jit345.swstokyo.dec.com
Sat Jan 19 15:08:20 AEST 1991


In article <1991Jan18.170921.4866 at resam.dk> andrew at resam.dk (Leif Andrew Rump) writes:

>#define	FOLDER	fk
>#ifdef	FOLDER
>  part 1
>#endif
>#if	FOLDER == fk
>  part 2
>#endif
>
>It worked OK for part 1 ... but part 2 get compiled under any circumstances
>
>#ifdef	FOLDER == CASE
>  part 2
>#endif
>
>So this rules out that the presence is equal 1 and absence equal 0!

Absence equals zero, yes.  Presence equals whatever the defined value is.
Now let's see what happens when you test
#if    FOLDER == fk
#if    fk     == fk
#if    0      == fk
#if    0      == 0
which is true.

#ifdef FOLDER == CASE
is syntactically invalid.  Assume you meant #if and let's see:
#if    FOLDER == CASE
#if    0      == CASE
#if    0      == 0

If you want a macro to evaluate to something other than 0, you must give
it a value (a replacement-list) that evaluates as a constant-expression.
Doug Gwyn already posted correct examples.

--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.



More information about the Comp.std.c mailing list