This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: preprocessing question


Yes. You are right.


----- Original Message ----- From: "Andreas Schwab" <schwab@suse.de>
To: "Michael Gong" <mwgong@cs.toronto.edu>
Cc: "Jan Beulich" <jbeulich@novell.com>; <gcc@gcc.gnu.org>
Sent: Monday, September 25, 2006 12:08 PM
Subject: Re: preprocessing question



"Michael Gong" <mwgong@cs.utoronto.ca> writes:

One explanation could be:

----- Original Message ----- From: "Jan Beulich" <jbeulich@novell.com>
To: <gcc@gcc.gnu.org>
Sent: Monday, September 25, 2006 11:23 AM
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)

since "x" is already defined as a object-like macro, "x" is replaced by "alt_x", so this essentially is: #define alt_x(p) alt_x(p+1)

Since C99 (6.10.3.9) describes:
... defines an object-like macro that causes each subsequent instance of
the macro name to be replaced by the replacement list of preprocessing
tokens that constitute the remainder of the directive.

Macro expansion does not operate on preprocessing directives unless noted otherwise.

Andreas.

--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]