This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
preprocessing question
- From: "Jan Beulich" <jbeulich at novell dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Mon, 25 Sep 2006 17:23:34 +0200
- Subject: preprocessing question
Can anyone set me strait on why, in the following code fragment
int x(unsigned);
struct alt_x {
unsigned val;
};
#define x alt_x
#define alt_x(p) x(p+1)
int test(struct x *p) {
return x(p->val);
}
the function invoked in test() is alt_x (rather than x)? I would have
expected that the preprocessor
- finds that x is an object like macro, and replaces it with alt_x
- finds that alt_x is a function-like macro and replaces it with x(...)
- finds that again x is an object like macro, but recognizes that it
already participated in expansion, so doesn't replace x by alt_x a
second time.
Our compiler team also considers this misbehavior, but since I
tested three other compilers, and they all behave the same, I
continue to wonder if I'm mis-reading something in the standard.
Thanks a lot, Jan