[comp.lang.c] Answers to 'can I nest comments?'

rfink@eng.umd.edu (Russell A. Fink) (10/12/90)

Just a follow-up note to the question I asked a couple of days back.
Thanks to all who gave answers. For the record, the unanimous
concensus was that nested comments become whitespace, or, more
specifically, 
     printf( "The value of number is: %d.\n", num/* this is obnoxious */ber );
becomes
     printf( "The value of number is: %d.\n", num ber );

HOWEVER, that is just the standard implementation. Several compilers will
reportedly generate
     printf( "The value of number is: %d.\n", number );

although, by K&R et. al., there are no guarantees.

"What in hades would you want with that", you ask? Well, I am trying to make
a lex program to parse c input, or at least strip out comments, and no
mention was made on how this class project is supposed to handle such input;
I figured I'd try to mimick standard conventions as much as possible.

Thanks, usenauts!




--
   //=====   //=====   Russ Fink  ===============
  //        //____     rfink@eng.umd.edu        
 //        //          University of Maryland
//=====   //=====      College Park  ============

mccaugh@sunc7.cs.uiuc.edu (10/13/90)

Just because you received a consensus that comments get translated to white-
space doesn't make it the standard., which may explain why many compilers
fail to comply.

pfalstad@phoenix.Princeton.EDU (Paul John Falstad) (10/14/90)

In article <1990Oct12.164737.23574@eng.umd.edu> rfink@eng.umd.edu (Russell A. Fink) writes:
>Just a follow-up note to the question I asked a couple of days back.
>Thanks to all who gave answers. For the record, the unanimous
>concensus was that nested comments become whitespace, or, more
>specifically, 
>     printf( "The value of number is: %d.\n", num/* this is obnoxious */ber );
>becomes
>     printf( "The value of number is: %d.\n", num ber );
>
>HOWEVER, that is just the standard implementation. Several compilers will
>reportedly generate
>     printf( "The value of number is: %d.\n", number );
>
>although, by K&R et. al., there are no guarantees.

According to K&R2 (p229):

"comments are replaced by a single space."

So it is part of ANSI, not just the usual implementation.  Compilers that
do generate "number" are not ANSI-conformant.

The subject line for this thread is misleading, by the way.  "Nested
comments" are something different than what you're talking about.
"Comments embedded in identifiers" would be a better terminology.

--
pfalstad@phoenix.princeton.edu   The Germans are disputing it! Hegel is
arguing that the reality is merely an a priori adjunct of non-absolutistic
ethics; Kant, by the categorical imperative, is holding it ontologically
exists only in the imagination; and Marx is claiming it was off sides.

karl@haddock.ima.isc.com (Karl Heuer) (10/15/90)

In article <24700011@sunc7> mccaugh@sunc7.cs.uiuc.edu writes:
>Just because you received a consensus that comments get translated to white-
>space doesn't make it the standard., which may explain why many compilers
>fail to comply.

False in this specific case (both K&R 1 and ANSI say that comments are
whitespace), but true in general: the language is not defined by a
majority vote.

Karl W. Z. Heuer (karl@ima.isc.com or harvard!ima!karl), The Walking Lint

boyd@necisa.ho.necisa.oz (Boyd Roberts) (10/22/90)

In article <24700011@sunc7> mccaugh@sunc7.cs.uiuc.edu writes:
>
>Just because you received a consensus that comments get translated to white-
>space doesn't make it the standard., which may explain why many compilers
>fail to comply.

They always were white space.  It's just that some varients of cpp mashed
comments into nothing.  You must realise that (historically) cpp removed
comments, hence the -C option.  The language was always clear about
comments being white space.  cpp's bugs/features were another matter.


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''