Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"01-16-09 - push_macro & pop_macro"

5 Comments -

1 – 5 of 5
Blogger castano said...

GCC supports that as well:

http://gcc.gnu.org/onlinedocs/gcc/Push_002fPop-Macro-Pragmas.html

January 16, 2009 at 10:31 PM

Blogger Tom Johnstone said...

#define old_test test
#undef test
#define test whatever i want to do
#undef test
#define test old_test

January 17, 2009 at 12:15 AM

Anonymous Anonymous said...

Obviously what 800poundgames wrote doesn't work. There is a strategy to avoid the mess of knowing how to define it back to the original def, although you probably already know this:

#define THINGY_publicdef ...actual definition...
#define THINGY THINGY_publicdef

then in a place where you need to override it:

#undef THINGY
#define THINGY whatever

and then to undo it

#undef THINGY
#define THINGY THINGY_publicdef

January 17, 2009 at 12:38 AM

Blogger cbloom said...

Yeah, Sean, obviously that is what I do, but that doesn't work when you don't know which publicdef to do, eg. when you're mixing codebases.

The most common case where I hit this is with malloc or new. I think I'll write more about that case, but the basic issue is :

#undef new

.. do stuff with original new

#define new my_new

but if this is like inside an STL header, it can't know to use the "my_new" from cblib, etc.

January 17, 2009 at 8:53 AM

Blogger cbloom said...

BTW I wish you could pragmas inside #defines ; there's really no reason why not, #define is just text-sub.

January 17, 2009 at 8:54 AM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.