defining a comment?

will summers will.summers at p6.f18.n114.z1.fidonet.org
Sat Sep 17 08:38:53 AEST 1988


 
Len Reed writes:
 >Can I use the Preprocessor to define a comment?
 >
 >#define STARTCOM /*
 
No. (you were talking about ANSI right?). To resolve ambiguities ANSI defines 
"translation phases" that function as-if they are separate passes over the 
source file. Comments get replaced by a single whitespace character in "pass" 
3; preprocessing directives in "pass" 4.
 
 > #define COMMENT /*
 > #define CLOSE_COMMENT */
 >
 > The pre-processor considers these two lines to be functionally equivalent
 > to the single line:
 >
 > #define COMMENT /* #define CLOSE_COMMENT */
 
Yup.
 
 > which is no different than
 > #define COMMENT
 
Which is precisely what "pass" 4 sees.
 
 > COMMENT
 >         A whole bunch of stuff
 > CLOSE_COMMENT
 
Try:
 
#define COMMENT 0
 
#if COMMENT
  A whold bunch of stuff
#endif  /* CLOSE_COMMENT */
 
 
One might be tempted to:
 
#define COMMENT       #if 0
#define CLOSE_COMMENT #endif
 
But ANSI (Jan '88 draft) says
  3.8.3.4 Rescanning and further replacement
    ...
    The resulting completely macro-replaced preprocessing token sequence is 
 not processed as a preprocessing directive even if it resembles one.
 
#if 0
may not be pleasing to your sense of aesthetics, but it is a well recognized C 
idiom.  Use it for a while and COMMENT CLOSE_COMMENT is likely to
become as alien to your eye as  #if 0  is now...
 
If you are adament:  write the code as you wish and run it add a trivial
pre-compile pass that maps COMMENT to #if 0 to the compile script.
 
    \/\/ill <tm>
 


--  
St. Joseph's Hospital/Medical Center - Usenet <=> FidoNet Gateway
Uucp: ...{gatech,ames,rutgers}!ncar!noao!asuvax!stjhmc!18.6!will.summers



More information about the Comp.lang.c mailing list