How about a Lint warning for "while (no-side-effects) ;" ??

Marshall Cline cline at suntan.ece.clarkson.edu
Sat Jul 1 05:35:39 AEST 1989


In <441a30e5.8f55 at fiero.engin.umich.edu>, ejd at 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 at lll-winken.LLNL.GOV>, berry at 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 at yale-celray.yale.UUCP> Horne-Scott at 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 (<expr>)" 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 ( <expr> ) <body> ;"
whenever neither <expr> nor <body> has any side effects.
(Naturally a "for(e1; e2; e3) <b>"  loop would qualify as well, where the
warning would appear if neither <e2>, <e3>, nor <b> had any side effects.)

Another thought: the existence of a function call in <expr> or <body>
should cancel the warning since the funct could longjmp() out of the loop.

Marshall
--
	________________________________________________________________
	Marshall P. Cline	ARPA:	cline at sun.soe.clarkson.edu
	ECE Department		UseNet:	uunet!sun.soe.clarkson.edu!cline
	Clarkson University	BitNet:	BH0W at CLUTX
	Potsdam, NY  13676	AT&T:	315-268-6591



More information about the Comp.lang.c mailing list