Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Constants in conditionals Message-ID: <912@caslon.cs.arizona.edu> Date: 20 Feb 91 05:23:54 GMT References: <9890@dog.ee.lbl.gov> <1991Feb18.113919.28217@watmath.waterloo.edu> <10032@dog.ee.lbl.gov> <1991Feb20.034136.14554@athena.mit.edu> Organization: U of Arizona CS Dept, Tucson Lines: 29 In article <1991Feb20.034136.14554@athena.mit.edu> scs@adam.mit.edu writes: >[...] >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. Actually, I had some interesting ideas about this when I was taking a compiler writing course a year ago. We could have several types (internally, of course) for "integer" expressions: definitiely_bool, possibly_bool, unlikely_bool. Operators like <, ==, >, &&, || would yeild types "definitely_bool". Simple integer values could be "possibly_bool", and other operators (especially =) would have type "unlikely_bool". That way, the expression in while(TRUE) would have type "possibly_bool", and if(i = 0) would have type "unlikely_bool". A lint implementation or aggressive compiler could then flag expressions having type "unlikely_bool" expressions occurring in a boolean context. -- Dave Schaumann | Is this question undecidable? dave@cs.arizona.edu |