C, embedded comments and preprocessors

Henry Spencer henry at zoo.toronto.edu
Fri Sep 21 01:50:02 AEST 1990


In article <9009191929.AA13849 at lilac.berkeley.edu> lwv27 at CAS.BITNET writes:
>...until it ran into a line like:
>
>lines of various text's comments
>
> ...
>Is it common for a preprocessor to disallow embedded comments?
>... I am just trying to decide if this is a unique
>occurance, fairly common, a required behavior by ANSI C stds now, etc.

ANSI C is quite explicit that everything outside comments (remembering
that comments do not nest in C, and never have) must be legal tokens,
or at least preprocessor tokens if inside the body of a "false" #if[][def]
(which is what you should be using to delete text).  There is some weasel-
wording which permits a compiler to be tolerant of lines like yours, *if*
they are inside a false #if, but this is not required behavior and relying
on it is not portable.

You should be using #if to "comment out" program text, and putting human-
language comments inside /* */.
-- 
TCP/IP: handling tomorrow's loads today| Henry Spencer at U of Toronto Zoology
OSI: handling yesterday's loads someday|  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list