home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / sgi / 18467 < prev    next >
Encoding:
Text File  |  1993-01-04  |  2.5 KB  |  71 lines

  1. Path: sparky!uunet!wupost!gumby!destroyer!gatech!swrinde!ctcvax.ccf.swri.edu!trident!noren
  2. Newsgroups: comp.sys.sgi
  3. Subject: Rules for naked ";" in ANSI "C"?
  4. Message-ID: <255@trident.datasys.swri.edu>
  5. From: noren@trident.datasys.swri.edu (Greg Noren)
  6. Date: 4 Jan 93 21:55:00 GMT
  7. Organization: Southwest Research Institute
  8. Lines: 61
  9.  
  10. I turned -fullwarn on some "C" code I was ANSIfying and tangled
  11. with a bothersome warning from cc().  Take a look at the
  12. following test program derived from the code in question.
  13. ----------
  14. #include "stdio.h"
  15. #if defined( DEBUG_ON )
  16. #    define D(x) (x)
  17. #else
  18. #    define D(x)
  19. #endif
  20.  
  21. void main( unsigned int argc,
  22.            char         **argv,
  23.            char         **envp )
  24. {
  25.     int i;
  26.  
  27.     for ( i = 0; i < 6; i++ )
  28.         printf( "Hello, world %d\n", i );
  29.  
  30.     D(printf("END TEST\n"));
  31. }
  32. ----------
  33. Compiling with:  "cc -o test -ansi -fullwarn test.c" produces
  34. an executable which runs correctly and the following accom
  35. warning for the "D(printf...);" macro line:
  36.  
  37. accom: Warning 302: test.c, line 17: bodyless for statement
  38.  
  39. Since DEBUG_ON is not defined, line 17 evaluated to a naked
  40. semicolon in the compiler pass.  Normally cc() appears to
  41. gobble them up without a complaint from what I've seen.
  42. But the presence of the preceeding "for" loop in the block
  43. seems to trigger the warning on the naked semicolon line.
  44. What's worse, stick a number of legitimate statements between
  45. the "for" loop and the "D(printf...);" macro line, and the
  46. same warning still generates for the naked semicolon line
  47. whereever it ends up.
  48.  
  49. I cured the naked semicolon and hushed the warning by removing
  50. the semicolon from the end of line 17 and appending it to the
  51. macro definition thusly:  "#    define D(x) (x);"  But you can
  52. also quiet the warning by enclosing the "printf" line (body of
  53. the "for" loop) in curley braces instead of correcting the
  54. macro definition.
  55.  
  56. I realize solitare semicolons have their uses (empty "while"
  57. and "for" loops, etc.).  Are arbitrary, naked ones (i.e. ones
  58. not really needed) legit?  Anticipating that this is
  59. _incorrect_ "C" programming, I got rid of them.  But the
  60. curley brace method of warning suppression bothers me.  It
  61. makes me think that cc() is confused more than it should be.
  62.  
  63. Any thoughts on this?
  64.  
  65. --
  66. I disclaim:  The words above are mine... My company speaketh their own.
  67.  
  68. Gregory Noren                             (512)522-5531 (a human)
  69. Southwest Research Institute              (512)522-5499 (just the FAX)
  70. Internet:  noren@trident.datasys.swri.edu (129.162.50.211)
  71.