Newsgroups: comp.lang.c
Path: utzoo!utgpu!watserv1!watmath!datangua
From: datangua@watmath.waterloo.edu (David Tanguay)
Subject: Re: Constants in conditionals
Message-ID: <1991Feb21.121452.29969@watmath.waterloo.edu>
Organization: University of Waterloo
References: <9890@dog.ee.lbl.gov> <1991Feb18.113919.28217@watmath.waterloo.edu> <858@isgtec.UUCP>
Date: Thu, 21 Feb 1991 12:14:52 GMT
Lines: 49

In article <858@isgtec.UUCP> robert@isgtec.UUCP (Robert Osborne) writes:
|datangua@watmath.waterloo.edu (David Tanguay) writes:
|> "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.
|Nice attitude towards programming;
|"I don't use any language constructs *I* don't find aesthetically pleasing"

Same one you're advocating: if( constant ) is a valid language construct
that you don't want anybody to use (i.e., you want the compile to warn
people off of it).

|I know that any compile dependency, whether for architecture, Unix type,
|or to exclude some feature (ie. debugging), will have an
|#if something
|#endif
|associated with it.

I still use ifdefs for these kinds of things (I want non-portable code to
stand out). The constants in ifs appear where one piece of source is
used for different programs (e.g., C code parser vs. lint). I'm currently
using it in a debugger to select between a debugger program, an
executable file editor, and a post mortem analyser.

|> I could also  use an external, but then I don't get
|> the dead code elimination.
|Oh now I see,  you left the smilee off your article.

No. On the architectures I have to work on, I need all the memory I can
get. Any functions that are called from dead code will not get linked
in, but if I switch on an external, they will.

Paul Tomblin 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.

Another case I've used is if( sizeof(int) < sizeof(long) ).
My constants are generally cpp macros created in an #ifdef in a
header somewhere. It's an aesthetic argument. Do you also not hire
programmers who use the wrong brace style?

Chris Torek writes:
| Well, a *really* good compiler will allow you to say `yes, I know
| this is a constant, but I want to test it anyway'.
| (This is one possible use for an ANSI `#pragma'.)

A command line switch is fine, but a #pragma sort of defeats the purpose
(unless you mean just one with file scope).
-- 
David Tanguay        datanguay@watmath.waterloo.edu        Thinkage, Inc.
