Re^2: Why nested comments not allowed?

Greg Conway gregory at ritcsh.cs.rit.edu
Fri Feb 23 04:47:25 AEST 1990


In article <5372 at ur-cc.UUCP> misu_ss at uhura.cc.rochester.edu (What`s in a name?) writes:
>This leads me to a question on how compilers work...
>Do #defines get worked out before comments are discarded...

The 'traditional' implementation is that #defines's are done by the
preprocessor and comments are handled by the scanner.  Under such a case, 
the #define's are handled first.

>#define OPEN_COMMENT "/*"
>#define CLOSE_COMMENT "*/"

	[ text deleted ]

>	string = OPEN_COMMENT;
>	printf("s% ", string);

	[ further text deleted]

According to K&R II, page 154, the behavior of this program is undefined.
(The correct format conversion is %s).  Assuming that the above is merely
a typo, then the output you got appears to me to be correct.

							- Greg


-- 
		Gregory Conway @ Computer Science House, RIT
"When I was young my father told me just bad guys die -- at that time just a
 little white lie. It was one of the first but it hurt me the most -- and the
 truth stung like tears in my eyes ... and even now it makes me cry." - Fish



More information about the Comp.lang.c mailing list