Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!image.soe.clarkson.edu!news From: cline@suntan.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c Subject: How about a Lint warning for "while (no-side-effects) ;" ?? Message-ID: Date: 30 Jun 89 19:35:39 GMT References: <328@tree.UUCP> <417@siswat.UUCP> <441a30e5.8f55@fiero.engin.umich.edu> <27729@lll-winken.LLNL.GOV> <65088@yale-celray.yale.UUCP> Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Organization: Clarkson University, Postdam NY Lines: 44 In-reply-to: Horne-Scott@cs.yale.edu's message of 29 Jun 89 17:44:54 GMT In <441a30e5.8f55@fiero.engin.umich.edu>, ejd@caen (Edward Driscoll) writes: >It [[ if(x==5); ]]is legal, but I would hope for a warning from such an >obvious semantic error. In <27729@lll-winken.LLNL.GOV>, berry@lll-crg (Berry Kercheval) writes: >Goodness, save me from useless warnings for perfectly good C >constructs. This is NOT an "obvious" semantic error. Have you never >done something like this? > while(!isspace(*cp++)); /* skip to end of word */ In <65088@yale-celray.yale.UUCP> Horne-Scott@cs.yale.edu (Scott Horne) writes: >`while' constructs with null bodies are useful, but `if' constructs like the >one above are not...... How about a change-of-subject: What about a side-effect-less expression in a while loop with an empty body? Ex: main() { int x = 0; while (x < MAX); f(x++); } The `;' after the "while ()" is of course the error here. The code is definitely wrong, since it will either do nothing or hang. Perhaps we'd be taxing lint's look-ahead ability here, but seemingly "lint" could warn for this kind of thing too. Thoughts? SPECIFICALLY: A warning could be issued with "while ( ) ;" whenever neither nor has any side effects. (Naturally a "for(e1; e2; e3) " loop would qualify as well, where the warning would appear if neither , , nor had any side effects.) Another thought: the existence of a function call in or should cancel the warning since the funct could longjmp() out of the loop. Marshall -- ________________________________________________________________ Marshall P. Cline ARPA: cline@sun.soe.clarkson.edu ECE Department UseNet: uunet!sun.soe.clarkson.edu!cline Clarkson University BitNet: BH0W@CLUTX Potsdam, NY 13676 AT&T: 315-268-6591