Xref: utzoo comp.lang.c++:12941 comp.lang.c:38442 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: Conditional #if preprocessor expressions Message-ID: <674@taumet.com> Date: 18 Apr 91 15:34:28 GMT References: <1849@dinl.mmc.UUCP> Followup-To: comp.lang.c++ Organization: Taumetric Corporation, San Diego Lines: 41 noren@dinl.uucp (Charles Noren) writes: >I have defined a macro symbol, INCL to be: > #define INCL apple >I then use INCL in the following expressions: > #if INCL == apple > #include "apple.h" > #endif > #if INCL == orange > #include "orange.h" > #endif >My expectation is that only the include file "apple.h" >is included. However, the include file "orange.h" is >included as well. Why is this? The preprocessor does not do string comparison, just integer arithmetic. The preprocessor rule is that if a name has not been #defined, its value is zero. So INCL is defined to be apple, which apparently has not been #defined. The value of apple is then 0, and so the value of INCL is 0, and the two are equal; "apple.h" is then #included. Next, INCL is compared to orange, which has not been #defined, so its value is 0, the same as the value of INCL; "orange.h" is then #included. What you want is something more along the lines of #define APPLE /* or ORANGE, or whatever */ #ifdef APPLE #include "apple.h" #endif #ifdef ORANGE #include "orange.h" #endif -- Steve Clamage, TauMetric Corp, steve@taumet.com