Skip to content

Instantly share code, notes, and snippets.

@dmatveev
Created November 17, 2013 18:23
Show Gist options
  • Save dmatveev/7516380 to your computer and use it in GitHub Desktop.
Save dmatveev/7516380 to your computer and use it in GitHub Desktop.
ProTip: scoped preprocessor definitions
#include <stdio.h>
/* #define FOO 33 */
#ifdef FOO
# pragma push_macro ("FOO")
# define FOO_WRAPPED
# undef FOO
#endif
#define FOO 100500
void foo()
{
printf ("Foo! %d\n", FOO);
}
#ifdef FOO_WRAPPED
# undef FOO
# undef FOO_WRAPPED
# pragma pop_macro ("FOO")
#endif
void bar()
{
#ifdef FOO
printf ("Bar! %d\n", FOO);
#endif
}
int main (int argc, char *argv[])
{
foo();
bar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment