home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!gumby!destroyer!gatech!swrinde!ctcvax.ccf.swri.edu!trident!noren
- Newsgroups: comp.sys.sgi
- Subject: Rules for naked ";" in ANSI "C"?
- Message-ID: <255@trident.datasys.swri.edu>
- From: noren@trident.datasys.swri.edu (Greg Noren)
- Date: 4 Jan 93 21:55:00 GMT
- Organization: Southwest Research Institute
- Lines: 61
-
- I turned -fullwarn on some "C" code I was ANSIfying and tangled
- with a bothersome warning from cc(). Take a look at the
- following test program derived from the code in question.
- ----------
- #include "stdio.h"
- #if defined( DEBUG_ON )
- # define D(x) (x)
- #else
- # define D(x)
- #endif
-
- void main( unsigned int argc,
- char **argv,
- char **envp )
- {
- int i;
-
- for ( i = 0; i < 6; i++ )
- printf( "Hello, world %d\n", i );
-
- D(printf("END TEST\n"));
- }
- ----------
- Compiling with: "cc -o test -ansi -fullwarn test.c" produces
- an executable which runs correctly and the following accom
- warning for the "D(printf...);" macro line:
-
- accom: Warning 302: test.c, line 17: bodyless for statement
-
- Since DEBUG_ON is not defined, line 17 evaluated to a naked
- semicolon in the compiler pass. Normally cc() appears to
- gobble them up without a complaint from what I've seen.
- But the presence of the preceeding "for" loop in the block
- seems to trigger the warning on the naked semicolon line.
- What's worse, stick a number of legitimate statements between
- the "for" loop and the "D(printf...);" macro line, and the
- same warning still generates for the naked semicolon line
- whereever it ends up.
-
- I cured the naked semicolon and hushed the warning by removing
- the semicolon from the end of line 17 and appending it to the
- macro definition thusly: "# define D(x) (x);" But you can
- also quiet the warning by enclosing the "printf" line (body of
- the "for" loop) in curley braces instead of correcting the
- macro definition.
-
- I realize solitare semicolons have their uses (empty "while"
- and "for" loops, etc.). Are arbitrary, naked ones (i.e. ones
- not really needed) legit? Anticipating that this is
- _incorrect_ "C" programming, I got rid of them. But the
- curley brace method of warning suppression bothers me. It
- makes me think that cc() is confused more than it should be.
-
- Any thoughts on this?
-
- --
- I disclaim: The words above are mine... My company speaketh their own.
-
- Gregory Noren (512)522-5531 (a human)
- Southwest Research Institute (512)522-5499 (just the FAX)
- Internet: noren@trident.datasys.swri.edu (129.162.50.211)
-