Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!samsung!sol.ctr.columbia.edu!lll-winken!unixhub!shelby!msi-s0.msi.umn.edu!cs.umn.edu!sialis!quad!dts From: dts@quad.sialis.mn.org (David T. Sandberg) Newsgroups: comp.lang.c Subject: Re: Using a define that hasn't been #defined Message-ID: <609@quad.sialis.mn.org> Date: 3 Oct 90 08:47:07 GMT References: <5101@hsv3.UUCP> <1990Oct3.022132.9245@ux1.cso.uiuc.edu> Reply-To: dts@quad.sialis.mn.org (David T. Sandberg) Organization: Quadric Systems, Richfield MN Lines: 53 In article <1990Oct3.022132.9245@ux1.cso.uiuc.edu> gordon@osiris.cso.uiuc.edu (John Gordon) writes: > In fact, there is a very good way to avoid this kind of error: use the >compiler directives #ifdef and #ifndef. These check to see if a given >identifier has or has not been #define'd. I'm not the one who asked about this in the first place, but I really don't see how that would be expected to alleviate the situation. You see, I recently encountered a bug of a similar character (heh), as follows: #define SYSV { ... #ifdef SYSY ... #endif ... } In this situation, whether you use #if or #ifdef doesn't make any difference. To exasperate the situation, I was using a terminal upon which capital 'V's and 'Y's look even more similar than normal, and the problem resulting from the #ifdef-ed code's absence only manifested itself much later, in another module entirely separate from the one where the bug was hiding. That one took days, and large chunks of my hair, to find. B-( I suppose that, if one is very concerned about this and is using an ANSI-compliant preprocessor, one could do something like this: #include #define SYSV 1 #define DOS 2 #define OSTYPE SYSV main() { #if OSTYPE == SYSV printf( "This is the System V-specific code.\n" ); #elif OSTYPE == DOS printf( "This is the System V-specific code.\n" ); #else #error OSTYPE undefined or mistyped #endif } -- \\ David Sandberg \ ,=, ,=, \\ // dts@quad.sialis.mn.org / | |uadric '=,ystems // \\ uunet!rosevax!sialis!quad!dts \ '=\ `=' \\