Serious error-causing change in new CPP's -traditional behavior
Jason R Thorpe
thorpej@zembu.com
Mon May 8 14:46:00 GMT 2000
On Sat, May 06, 2000 at 12:18:29PM -0700, Zack Weinberg wrote:
> Thanks, I've added it.
Great.
> You might try converting whichever file this is to ANSI macro syntax.
> Support for preprocessing assembly language in nontraditional mode has
> been improved a lot recently.
Yah, eventually, I'd like to do that. However, since I know the code in
question is being built with at least 3 different versions of the compiler
right now (EGCS 1.1.2 release, a hacked GCC 2.95.2, and gcc-current), I'd
prefer to leave it as-is, at least until the next official release of
GCC.
> Hmm.
>
> Right now, comments in a #define line are silently discarded
> irrespective of -C, and I'm not sure what happens to comments in the
> arguments of a macro (probably the same thing). I've never heard of
> -CC before, but I'd be inclined to make that the behavior of -C. What
> does your -C do with comments in the macro definition?
Okay, using EGCS-1.1.2 plus the -CC option (who's description in the
manpage I quoted seems to be a bit misleading) added by Christos Zoulas
to that compiler's cccp, here is the output of the following test case:
----- snip -----
#define FOO(x) \
do { \
/* This is a comment. */ \
if ((x) > 0) \
foo((x)); \
} while (/*CONSTCOND*/0)
void func(int arg)
{
FOO(arg);
}
----- snip -----
CASE 1:
dr-evil:thorpej 142$ /usr/libexec/cpp -lang-c cpp-comments.c
# 1 "cpp-comments.c"
void func(int arg)
{
do { if (( arg ) > 0) foo(( arg )); } while ( 0) ;
}
CASE 2:
dr-evil:thorpej 143$ /usr/libexec/cpp -lang-c -C cpp-comments.c
# 1 "cpp-comments.c"
/* This is a comment. *//*CONSTCOND*/
void func(int arg)
{
do { if (( arg ) > 0) foo(( arg )); } while ( 0) ;
}
CASE 3:
dr-evil:thorpej 144$ /usr/libexec/cpp -lang-c -CC cpp-comments.c
# 1 "cpp-comments.c"
/* This is a comment. *//*CONSTCOND*/
void func(int arg)
{
do { /* This is a comment. */ if (( arg ) > 0) foo(( arg )); } while (/*CONSTCOND*/0) ;
}
> There used to be commented-out support for recognizing lint comments
> and transforming them into #pragmas - the above would become (using
> the C99 _Pragma notation)
>
> #define FOO do { statement1; statement2; } while (_Pragma("lint CONSTCOND")0)
There are two problems with this:
(1) It relies on a particular version of lint(1) recognizing
`#pragma lint ...' or `_Pragma("lint ...")'. Some people
can't always update their tools.
(2) Each time a particular version of lint(1) is taught about
a new lint comment, the preprocessor has to be updated.
> It was commented out because no one ever made use of the transformed
> annotations, and because we didn't know the real syntax of a lint
> comment (it had a finite list of switches it recognized). Would that
> be more useful to your lint? It could then use cpp's comment
> stripper, too.
I don't think there's a "real syntax" to a lint comment :-) It seems to
be:
/*<space optional>directive<matching space>*/
...and the directive part is particular to a given version of lint(1), tho
there some historic common ground for most lint(1) implementations.
--
-- Jason R. Thorpe <thorpej@zembu.com>
More information about the Gcc-bugs
mailing list