Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include "A.h"
- ...
- A a(...)
- ...
- std::max(x, y); // oops, problem since max is defined as macro in c_library.h
- ...
- //A.h
- #include "c_library.h"
- class A{
- public:
- A(...);
- static void callbackForCLibrary(datatypeOfCLibrary d){...}
- private:
- private datatypeOfCLibrary1;
- private datatypeOfCLibrary2;
- }
- #ifndef WRAP_C_LIBRARY_H
- #define WRAP_C_LIBRARY_H
- #include "c_library.h"
- #undef TROUBLESOME_MACRO_FROM_C_LIBRARY
- #endif // WRAP_C_LIBRARY_H
- #define A(X, Y) [X ; Y]
- #define B(X, Y) {X...Y}
- #define C this is C
- #define D this is D
- gcc -undef -dN -E foo.h > undef_foo.h
- sed -i ".bak" 's/#define[ t]([A-Za-z0-9_]*)/#undef 1/g' undef_foo.h
- gcc -undef -dD -E - < /dev/null >> undef_foo.h
- sed -i ".bak" '/#[du]/!d' undef_foo.h
- #undef __STDC__
- #undef __STDC_HOSTED__
- #undef __DYNAMIC__
- #undef A
- #undef B
- #undef C
- #undef D
- #define __STDC__ 1
- #define __STDC_HOSTED__ 1
- #define __DYNAMIC__ 1
- #include "foo.h"
- #include "undef_foo.h"
- A(1, 2)
- B(3, 4)
- C
- D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement