I answered a question a while ago about appending to C macros at Can I append to a preprocessor macro?
As the answer says, the following works in both clang and g++, but not in msvc
#define pushfoo _Pragma("push_macro(\"foo\")") //for convenience
#define popfoo _Pragma("pop_macro(\"foo\")") //I tried __pragma and __Pragma for msvc as well
#define foo 1
pushfoo //push the old value
#undef foo //so you don't get a warning on the next line
#define foo popfoo foo , 2 //append to the previous value of foo
pushfoo
#undef foo
#define foo popfoo foo , 3
pushfoo
#undef foo
#define foo popfoo foo , 4
foo //this whole list will expand to something like popfoo foo popfoo foo popfoo foo , 4
//which will in turn expand to 1 , 2 , 3 , 4
foo //the second time this will expand to just 1
While this does seem to work, I want to know if this is just something that happens to work out for gcc and clang, but msvc is also (or only) correct, or if the behavior they exhibit is the behavior mandated by the language specification. I am interested in both C and C++ if they differ (mostly interested in the newest editions, C18 and C++17 at the time of writing)