Home > C++, VC++ > Saving value of a MACRO( #define ) before redefining!

Saving value of a MACRO( #define ) before redefining!

Use push_macro and pop_macro to save and restore the value of a macro before redifining the same to some other value.

Here is a sample from MSDN…

// pragma_directives_pop_macro.cpp
// compile with: /W1
#include <stdio .h>
#define X 1
#define Y 2 

int main()
{
   printf("%d",X);
   printf("n%d",Y);
   #define Y 3   // C4005
   #pragma push_macro("Y")
   #pragma push_macro("X")
   printf("n%d",X);
   #define X 2   // C4005
   printf("n%d",X);
   #pragma pop_macro("X")
   printf("n%d",X);
   #pragma pop_macro("Y")
   printf("n%d",Y);
}// End main

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: