#pragma pop_macro("int")#include <iostream>
using namespace std;
#define int double
void main()
{
int iOne = 1;
cout << sizeof(iOne) << endl;
#pragma push_macro("int")
#undef int
int iTwo = 2;
cout << sizeof(iTwo) << endl;
#pragma pop_macro("int")
}
#include <iostream>
using namespace std;
#define int double
void main()
{
int iOne = 1;
cout << sizeof(iOne) << endl;
#pragma push_macro("int")
#undef int
int iTwo = 2;
cout << sizeof(iTwo) << endl;
//#pragma pop_macro("int")
}
I have just tried on vs2017, nothing different.both have no warnings/errors, work fine, and have the same output:
8
4
So, my question is:
very rougly speaking, push_macro means "store the current definition of the macro", pop_macro means "restore the saved definition of the macro".
Both commands have meaning in the scope of current translation unit (i.e, current compiled cpp file and including headers).
So, if you don't call pop_macro, simply the definition of the macro will not be restored, which is perfectly allowed and doesn't imply UB.
The pop_macro you put at the end of sample "With pop_macro" will actually have no effect, since there is no code following it that will be compiled
Note that we are talking about something happening at compile time, not at runtime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With