Comment Syntax

Rex Jaeschke rex at aussie.COM
Sat Nov 10 11:51:50 AEST 1990


> In article <HAGERMAN.90Nov7193212 at rx7.ece.cmu.edu> hagerman at ece.cmu.edu (John Hagerman) writes:
> >Why didn't // ... newline comments make it into ANSI C?
> 

Let me suggest that you CANNOT add // comments to an ANSI C compiler 
WITHOUT some hacking. Consider the following example:

int i;	// this comment ends in a backslash \
int j;

f()
{
	i = j;	/* error: j is not declared */
} 

ANSI's phases of translation require that backslash/new-lines be 
processed BEFORE comments. In this case the 2 declaration lines would 
become:

int i;	// this comment ends in a backslash int j;

and the declaration of j would be treated as part of the comment.

So, for a future version of ANSI C to adopt //, they would have to 
either rearrange the phases of translation (unlikely since that would 
no longer be backwards compatible) or to treat // and /**/ comments 
differently and add a new phase for //.

Rex

----------------------------------------------------------------------------
Rex Jaeschke     |  Journal of C Language Translation  | C Users Journal
(703) 860-0091   |        2051 Swans Neck Way          | DEC PROFESSIONAL
uunet!aussie!rex |     Reston, Virginia 22091, USA     | Programmers Journal
----------------------------------------------------------------------------
Convener of the Numerical C Extensions Group (NCEG)
----------------------------------------------------------------------------



More information about the Comp.std.c mailing list