Xref: utzoo comp.lang.c++:12926 comp.lang.c:38396 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!spool.mu.edu!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: Conditional #if preprocessor expressions Message-ID: <5301@goanna.cs.rmit.oz.au> Date: 18 Apr 91 09:20:34 GMT References: <1849@dinl.mmc.UUCP> Followup-To: comp.lang.c Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 29 In article <1849@dinl.mmc.UUCP>, noren@dinl.uucp (Charles Noren) writes: > #define INCL apple > #if INCL == apple > #include "apple.h" > #endif > #if INCL == orange > #include "orange.h" > #endif It doesn't work. The reason is that, as stated in C manuals and textbooks, the operand of an #if directive is an *integer* constant expressions, and identifiers which are not defined as macros are in effect replaced by 0. Hence #if INCL == orange turns into #if apple == orange which behaves like #if 0 == 0 The answer is to make sure that apple and orange _are_ defined: #define apple 1 #define orange 2 some time before the first use of apple or orange. -- Bad things happen periodically, and they're going to happen to somebody. Why not you? -- John Allen Paulos.