Using a define that hasn't been #defined

James Seidman jls at hsv3.UUCP
Wed Oct 3 09:26:43 AEST 1990


Recently I've run into a couple of hard-to-track bugs because I have
a section of conditionally compiled code using a symbol which hasn't
been defined.  For example, take the trivial case of this "program"

-------

#define XYZZY 1

main() {
#if XYZZU
	printf("xyzzy\n");
#else
	printf("plugh\n");
#endif
}

------

Now, obviously that XYZZU was supposed to be an XYZZY, and I wanted to
conditionally compile the first piece of code, not the second.  But when
I compile this, it doesn't even give me a friendly warning, and just
assumes XYZZU is 0.  (Which, I understand, is in accordance with ANSI-
defined behavior.)

Now, my question is how other people avoid these same kinds of idiotic
mistakes?  Even if I put in "#if !defined(XYZZY)..." type things for
every define, it still wouldn't catch all typos.  There should be some
way to avoid this idiotic kind of error...
-- 
Jim Seidman (Drax), the accidental engineer.
"There's a certain freedom to being completely screwed." - The Freshman
UUCP: ames!vsi1!headland!jls
ARPA: jls%headland.UUCP at ames.nasa.arc.gov



More information about the Comp.lang.c mailing list