Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. //main.cpp
  2.  
  3. #include "A.h"
  4.  
  5. ...
  6. A a(...)
  7. ...
  8. std::max(x, y); // oops, problem since max is defined as macro in c_library.h
  9. ...
  10.  
  11. //A.h
  12. #include "c_library.h"
  13.  
  14. class A{
  15. public:
  16. A(...);
  17. static void callbackForCLibrary(datatypeOfCLibrary d){...}
  18. private:
  19. private datatypeOfCLibrary1;
  20. private datatypeOfCLibrary2;
  21. }
  22.  
  23. #ifndef WRAP_C_LIBRARY_H
  24. #define WRAP_C_LIBRARY_H
  25.  
  26. #include "c_library.h"
  27.  
  28. #undef TROUBLESOME_MACRO_FROM_C_LIBRARY
  29.  
  30. #endif // WRAP_C_LIBRARY_H
  31.  
  32. #define A(X, Y) [X ; Y]
  33. #define B(X, Y) {X...Y}
  34. #define C this is C
  35. #define D this is D
  36.  
  37. gcc -undef -dN -E foo.h > undef_foo.h
  38. sed -i ".bak" 's/#define[ t]([A-Za-z0-9_]*)/#undef 1/g' undef_foo.h
  39. gcc -undef -dD -E - < /dev/null >> undef_foo.h
  40. sed -i ".bak" '/#[du]/!d' undef_foo.h
  41.  
  42. #undef __STDC__
  43. #undef __STDC_HOSTED__
  44. #undef __DYNAMIC__
  45. #undef A
  46. #undef B
  47. #undef C
  48. #undef D
  49. #define __STDC__ 1
  50. #define __STDC_HOSTED__ 1
  51. #define __DYNAMIC__ 1
  52.  
  53. #include "foo.h"
  54. #include "undef_foo.h"
  55.  
  56. A(1, 2)
  57. B(3, 4)
  58. C
  59. D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement