Re^2: Why nested comments not allowed?

brian_helterline brianh at hpcvia.CV.HP.COM
Fri Feb 23 03:00:19 AEST 1990


misu_ss at uhura.cc.rochester.edu (What`s in a name?) writes:

> {deleted}

>This leads me to a question on how compilers work...

>Do #defines get worked out before comments are discarded...

>I.E.  if I write code thus:

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

>main()
>{
>char *string[30]

>	string = OPEN_COMMENT;
>	printf("s% ", string);
>	string = "This is a C comment";
>	printf("s% ", string);
>	string = CLOSE_COMMENT;
>	printf("s%\n", string);

>}

>will this produce the output:

>/* This is a C comment */

>or will it simply do a newline and make string point to the return value of
>printf? (likely causing a seg fault if string is ever assigned again...)

>On gcc version 1.36 and cc (don't know version) running under SunOS4.0.3
>this code produces the first output.  Any compilers out there that do comment
>checking after filling out macros? 

>If this always works then this is a possible solution to the problem...
>Obviously, you'll have to use string functions but is that so bad?  If you
>are doing something that will output C code it's going to be pretty general
>in nature... There won't be a lot of cases where constant output is easiner
>than variable output. 

>						--mike


	On my compiler (MSC 5.1), it produced a syntax error!

	The line variable string should be declared as:

		char *string;

	not
		char *string[30]  /* no semicolon */


-- 
Mic3hael Sullivan,                    Society for the Incurably Pompous
		     		-*-*-*-*- 
...I know there are people in the world who do not love their fellow human
beings and I *HATE* people like that!  		--Tom Lehrer
----------



More information about the Comp.lang.c mailing list