Article View: gnu.gcc.bug
Article #2896gcc-cpp: nested expansion / stringification problem
From: Ken Raeburn
Date: Sun, 25 Feb 1990 08:16
Date: Sun, 25 Feb 1990 08:16
109 lines
3985 bytes
3985 bytes
(1.37, vax)
I think cpp is expanding the following code incorrectly:
/*
* test of cpp
*/
#include "./assert.h" /* running in 1.37 src directory */
#define A(X) (assert(X))
#define X1(X) (A(X), X.one)
#define X2(X) (A(X), X.two)
#define X3(X) (A(X), X.three)
#define X4(X) (A(X), X.four)
foo (X) {
return X4 (X3 (X2 (X1 (X))));
}
The output contains strings with `\' characters before double-quotes
only doubled, rather than tripled as would be necessary to get the
correct string values.
(In the original code, I wanted the pre-substitution text of the
argument in the string, obviously, but the macros I was writing were
evolving in the wrong direction.)
[multics!raeburn]
{/mit/gnu/dev/build/vax-gcc-1.37}
<1002 3:09am> % ./cpp -v foo.c
GNU CPP version 1.37
foo.c:14: only 2 args to macro `__assert'
foo.c:14: unterminated string or character constant
foo.c:0: unterminated macro call
foo.c:16: only 2 args to macro `__assert'
# 1 "foo.c"
# 1 "/mit/gnu/vaxlib/gcc-include/./assert.h" 1
void __eprintf ();
void abort();
# 5 "foo.c" 2
foo (X) {
return ((((((((((((((((X) ? 0 : (__eprintf ("Failed assertion " "X" " at line %d of `" "foo.c" "'.\n", 14), abort ()) ) ) , X.one) ) ? 0 : (__eprintf ("Failed assertion " "((((X) ? 0 : (__eprintf (\"Failed assertion \" \"X\" \" at line %d of `\" \"foo.c\" \"'.\\n\", 14), abort ()))), X.one)" " at line %d of `" "foo.c" "'.\n", 14), abort ()) ) ) , ((((X) ? 0 : (__eprintf ("Failed assertion " "X" " at line %d of `" "foo.c" "'.\n", 14), abort ()) ) ) , X.one) .two) )
? 0 : (__eprintf ("Failed assertion " "((((((((X) ? 0 : (__eprintf (\"Failed assertion \" \"X\" \" at line %d of `\" \"foo.c\" \"'.\\n\", 14), abort ()))), X.one)) ? 0 : (__eprintf (\"Failed assertion \" \"((((X) ? 0 : (__eprintf (\\"Failed assertion \\" \\"X\\" \\" at line %d of `\\" \\"foo.c\\" \\"'.\\\\n\\\", 14), abort ()))), X.one)\" \" at line %d of `\" \"foo.c\" \"'.\\n\" " at line %d of `" 14 "'.\n", ), abort ()) , abort ())))) ? 0 : (__eprintf ("Failed as!
sertion " "((((((((((((X) ? 0 : (_
_eprintf (\"Failed assertion \" \"X\" \" at line %d of `\" \"foo.c\" \"'.\\n\", 14), abort ()))), X.one)) ? 0 : (__eprintf (\"Failed assertion \" \"((((X) ? 0 : (__eprintf (\\"Failed assertion \\" \\"X\\" \\" at line %d of `\\" \\"foo.c\\" \\"'.\\\\n\\\", 14), abort ()))), X.one)\" \" at line %d of `\" \"foo.c\" \"'.\\n\" " at line %d of `" 14 "'.\n", ), abort ()) , abort ()))), ((((X) ? 0 : (__eprintf (\"Failed assertion \" \"X\" \" at line %d of `\" \"foo.c\" \"'.\\n\", 14), abort ()))), X.on
e).two)) ? 0 : (__eprintf (\"Failed assertion \" \"((((((((X) ? 0 : (__eprintf (\\"Failed assertion \\" \\"X\\" \\" at line %d of `\\" \\"foo.c\\" \\"'.\\\\n\\\", 14), abort ()))), X.one)) ? 0 : (__eprintf (\\\"Failed assertion \\\" \\\"((((X) ? 0 : (__eprintf (\\\\\"Failed assertion \\\\\" \\\"X\\\\\" \\\" at line %d of `\\\\\" \\\"foo.c\\\\\" \\\"'.\\\\\\\\n\\\\\\\", 14), abort ()))), X.one)\\\" \\\" at line %d of `\\\" \\\"foo.c\\\" \\\"'.\\n\\" \" at line %d of `\" 14 \!
"'.\\n\", ), abort ()), abort ()))
)", "foo.c", 16)) ) Exit 33 ./cpp -v foo.c
[multics!raeburn]
{/mit/gnu/dev/build/vax-gcc-1.37}
<1003 3:09am> % exit
[multics!raeburn]
{/mit/gnu/dev/build/vax-gcc-1.37}
<1004 3:10am> %
script done on Sun Feb 25 03:10:06 1990
Technical Details
Message-ID:
<9002250816.AA08600@HODGE.MIT.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!iuvax!cica!tut.cis.ohio-state.edu!ATHENA.MIT.EDU!RaeburnShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!iuvax!cica!tut.cis.ohio-state.edu!ATHENA.MIT.EDU!Raeburn From: Raeburn@ATHENA.MIT.EDU (Ken Raeburn) Newsgroups: gnu.gcc.bug Subject: gcc-cpp: nested expansion / stringification problem Message-ID: <9002250816.AA08600@HODGE.MIT.EDU> Date: 25 Feb 90 08:16:51 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 103