Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!bloom-beacon!bloom-picayune.mit.edu!news From: scs@adam.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: Constants in conditionals Message-ID: <1991Feb20.034136.14554@athena.mit.edu> Date: 20 Feb 91 03:41:36 GMT References: <9890@dog.ee.lbl.gov> <1991Feb18.113919.28217@watmath.waterloo.edu> <10032@dog.ee.lbl.gov> Sender: news@athena.mit.edu (News system) Reply-To: scs@adam.mit.edu Organization: Thermal Technologies, Inc. Lines: 35 In article <10032@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes: >>In article <9890@dog.ee.lbl.gov> I wrote: >>>... these are effectively the same as `if (0)', hence a good compiler >>>should warn about a constant in conditional context [...] > >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'.) Actually, if I were writing lint, I'd have it complain by default about "constant in conditional context" only for compile-time constant (nontrivial) expressions, not compile-time constant CONSTANTS. The "constant in conditional context" message is merely one weapon in our arsenal against that all-time most common C bug: if(i = 0) (I still get bit by this from time to time, whether from sticky keyboards or sticky fingers I'm not sure.) However, constructions like while(TRUE) are so common that it seems better not to warn about them. (A useful distinction between if(constant) and while(constant) could probably be made, since intentional usages of if(constant) are quite a bit less common. Chris is right; the best compilers/lints would give you fine control over this stuff, if they're into quality warning messages.) Steve Summit scs@adam.mit.edu