Orphaned Response

dougm at ico dougm at ico
Mon Jun 30 02:32:00 AEST 1986


/* Written  1:46 pm  Jun 27, 1986 by rbutterworth at watmath.UUCP in ico:net.lang.c */
/* ---------- "Re: #if foo vs #if defined(foo)" ---------- */

> A CPP which silently takes undefined symbols to be 0 can be quite
> dangerous.  Consider the following case with these definitions
...

> "#if squat||(3*y)".

> I think the effort of having to use "#ifdef x" or "#if defined(x)"
> instead of lazily using "#if x" is well worth it.

I have to agree.  Another sloppy practice I've come across is not
using the "&&" and "||" but using "&" and "|" as equivalent to the
doubled form.  Then you end up spending time searching for a problem
when someone changes a
	#define token
to
	#define token 2
and having the 
	#if token&token2
suddenly not work.  Using the defined(token) construct when you only
care about defined or not defined can save more time than the time it
takes to type it in.

Of course, you still have the people who think that
	#ifdef token&token2
does the same thing as
	#if defined(token)&&defined(token2)



More information about the Comp.lang.c mailing list