Discussion:
Macro expansions
(too old to reply)
Vladimir Grigoriev
2008-05-20 11:58:28 UTC
Permalink
What does control of the order of macro expansions according to the
standard: the order in which macros were defined or the order in which
macros were encountered in code base?

Vladimir Grigoriev
Chris Uzdavinis (TeamB)
2008-05-20 13:07:33 UTC
Permalink
Post by Vladimir Grigoriev
What does control of the order of macro expansions according to the
standard: the order in which macros were defined or the order in which
macros were encountered in code base?
At the point of expansion, it uses whatever the current defintion is.


Normally it's the order the macros are defined (later replacing
earlier definitions, but you're supposed to undefine things before
redefining them.) But if you use the macro between two competing
definitions, it depends on whichever definition it processed last.
(You can accomplish some weird results with recursive includes and
conditional compilation, to make truly incomprehensible preprocessor
"meta programming".
--
Chris (TeamB);
Vladimir Grigoriev
2008-05-20 15:38:32 UTC
Permalink
Post by Chris Uzdavinis (TeamB)
At the point of expansion, it uses whatever the current defintion is.
Normally it's the order the macros are defined (later replacing
earlier definitions, but you're supposed to undefine things before
redefining them.) But if you use the macro between two competing
definitions, it depends on whichever definition it processed last.
(You can accomplish some weird results with recursive includes and
conditional compilation, to make truly incomprehensible preprocessor
"meta programming".
The situation is following. I have two macros. One looks like

#define ABC a, b, c

And another looks like

#define XY( x, y ) \
if ( y )
bla,bla,bla
else
bla,bla,bla

And in code there is the following statement

XY( ABC, z );

I want to be sure that the result will be

if ( z )
bla,bla,bla
else
bla,bla,bla

and I will not get compilation errors when the macro XY will be expanded.

Vladimir Grigoriev
Vladimir Grigoriev
2008-05-20 16:29:50 UTC
Permalink
Sorry, I omited backslashes. Should be of cource
#define XY( x, y ) \
if ( y ) \
bla,bla,bla \
else \
bla,bla,bla

Vladimir Grigoriev
Chris Uzdavinis (TeamB)
2008-05-20 16:47:56 UTC
Permalink
Post by Vladimir Grigoriev
Sorry, I omited backslashes. Should be of cource
#define XY( x, y ) \
if ( y ) \
bla,bla,bla \
else \
bla,bla,bla
You can run code through just the preprocessor and examine the
results, if you'd like. I think the -E flag does this, IIRC.
--
Chris (TeamB);
Dennis Cote
2008-05-22 22:50:50 UTC
Permalink
Post by Chris Uzdavinis (TeamB)
You can run code through just the preprocessor and examine the
results, if you'd like. I think the -E flag does this, IIRC.
Or you can right click on the file in the project manager and select
Preprocess.

HTH
Dennis Cote
Chris Uzdavinis (TeamB)
2008-05-23 14:23:55 UTC
Permalink
Post by Dennis Cote
Post by Chris Uzdavinis (TeamB)
You can run code through just the preprocessor and examine the
results, if you'd like. I think the -E flag does this, IIRC.
Or you can right click on the file in the project manager and select
Preprocess.
I'm a command line person living in an IDE world. :)
--
Chris (TeamB);
dhoke
2008-05-23 15:17:54 UTC
Permalink
Post by Chris Uzdavinis (TeamB)
Post by Chris Uzdavinis (TeamB)
You can run code through just the preprocessor and examine the
results, if you'd like. I think the -E flag does this, IIRC.
I'm a command line person living in an IDE world. :)
Never noticed -E, but you can also (at least used to could, haven't tried
lately) call cpp32 (c-pre-processor), I think pretty much in place of
bcc32...

Alex Bakaev [TeamB]
2008-05-20 16:45:07 UTC
Permalink
Post by Vladimir Grigoriev
and I will not get compilation errors when the macro XY will be expanded.
You can always take a look at the pre-processed file.

In any case, there don't appear to be any 'competing' macro definitions.
Loading...