[comp.lang.c] Constants in conditionals, was Re: Are enums safe to use in portable code?

datangua@watmath.waterloo.edu (David Tanguay) (02/18/91)

In article <9890@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes:
>Both of these are effectively the same as `if (0)', hence a good compiler
>should warn about a constant in conditional context [...]

Oooo I hope not! I occasionally use constants in ifs.
"if( PATCH_MODE ) { ... }", where PATCH_MODE is a cpp macro (0 or 1).
I know I coud use #if (or #ifdef), but I find them too ugly. I could also
use an external, but then I don't get the dead code elimination.
-- 
David Tanguay            Software Development Group, University of Waterloo

pt@geovision.gvc.com (Paul Tomblin) (02/19/91)

datangua@watmath.waterloo.edu (David Tanguay) writes:
>Oooo I hope not! I occasionally use constants in ifs.
>"if( PATCH_MODE ) { ... }", where PATCH_MODE is a cpp macro (0 or 1).
>I know I coud use #if (or #ifdef), but I find them too ugly. I could also
>use an external, but then I don't get the dead code elimination.

TOO UGLY!  Don't come applying for a job here!  Anybody who doesn't know
how to use all the BASIC aspects of the C compiler, and relys on optimizations
that probably aren't done on most of our machines (pcc based compilers) isn't
going to be too popular at this company, and probably many many others.

Sorry, but #ifdef or #if is SOOO basic, that if you don't know how to use
it (or refuse to for wierd reasons), you loose.
-- 
Paul Tomblin, Department of Redundancy Department.       ! My employer does 
The Romanian Orphans Support Group needs your help,      ! not stand by my
Ask me for details.                                      ! opinions.... 
pt@geovision.gvc.com or {cognos,uunet}!geovision!pt      ! Me neither.

henry@zoo.toronto.edu (Henry Spencer) (02/21/91)

In article <1424@geovision.gvc.com> pt@geovision.gvc.com writes:
>Sorry, but #ifdef or #if is SOOO basic, that if you don't know how to use
>it (or refuse to for wierd reasons), you loose.

There are lots of good reasons to avoid using #if/#ifdef if humanly possible.
Just look at some of the code that comes out of the more enthusiastic #ifdef
factories if you don't believe me.  However, using constants in ifs does not
solve the problem; what is needed is a change in approach, not quibbling over
the exact syntax of the conditionals.
-- 
"Read the OSI protocol specifications?  | Henry Spencer @ U of Toronto Zoology
I can't even *lift* them!"              |  henry@zoo.toronto.edu  utzoo!henry