Xref: utzoo comp.lang.c++:12906 comp.lang.c:38367 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!dinl!noren From: noren@dinl.uucp (Charles Noren) Newsgroups: comp.lang.c++,comp.lang.c Subject: Conditional #if preprocessor expressions Message-ID: <1849@dinl.mmc.UUCP> Date: 17 Apr 91 16:47:45 GMT Reply-To: noren@dinl.UUCP (Charles Noren) Organization: Martin Marietta I&CS, Denver CO. Lines: 82 This is my day to ask stupid questions.... 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? (I know there must be an obvious answer...) BTW, some examples in nihcl use this construct. See ex11-1.c under the ex directory. My environment: o Sun Spac station 2. o SunOS 4.1.1 o Saber C++ 1.0 o also compiled under the default Sun cc. Sample program: ======main.c================================== /* * File: main.c * */ #define INCL apple #if INCL == apple #include "apple.h" #endif #if INCL == orange #include "orange.h" #endif #include char* myString = FRUIT; main() { printf("myString = [%s].\n", myString); } ============================================== ======apple.h================================= /* File: apple.h */ #define FRUIT "apple" ============================================== ======orange.h================================ /* File: orange.h */ #define FRUIT "orange" ============================================== Thanks, -- Chuck Noren NET: dinl!noren@ncar.ucar.edu US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260, Denver, CO 80201-1260 Phone: (303) 977-1646