Xref: utzoo comp.os.vms:40177 comp.lang.c:40297 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!samsung!uunet!zephyr.ens.tek.com!tektronix!reed!elbaum From: elbaum@reed.UUCP (Daniel Elbaum) Newsgroups: comp.os.vms,comp.lang.c Subject: Re: problem with /define in VAX C: help! Message-ID: <16526@reed.UUCP> Date: 21 Jun 91 00:28:25 GMT References: <1991Jun20.030147.3867@athena.mit.edu> Distribution: usa Organization: Reed College, Portland OR Lines: 43 In <1991Jun20.030147.3867@athena.mit.edu> mlevin@jade.tufts.edu writes: : I have the following problem. I want to do conditional compilation, : based on the value of a variable given at compile time... if I have the program: : main() : { : enum {AA, BB, CC} dd; : dd = DEF; : #if DEF!=CC : printf("%d\n",dd); : #endif : } [and DEF is defined as BB on the compiler's command line, a Unix compiler includes the printf but Vax C doesn't.] You won't be able to count on the availability of enumeration constants at compile time. Standard C even guarantees that enumeration constants *don't* exist in the phase in which conditional inclusion is evaluated (sec. 3.8.1, esp. footnote). If the condition really needs to be evaluated at compile time rather than run time, then using #defines rather than enums is likely the most straightforward way out. But the code can remain almost the same if you postpone evaluation until run time: main() { enum {AA, BB, CC} dd; dd = DEF; if (DEF != CC) printf("%d\n",dd); } Note that this code will fail to compile if DEF is not defined. -- : Daniel Elbaum Responsible for all : tektronix!reed!elbaum disclaimed postings : elbaum@reed.edu