Escaping a # symbol in a #define macro?

It is possible to insert a hash token into the preprocessed token stream. You can do it as follows: #define MACRO(hash, name) hash include name MACRO(#,”hello”) —expands to: # include “hello” However, the standard explicitly rules out any further analysis of such line for the existence of preprocessing directives [cpp.rescan]: The resulting completely macro-replaced preprocessing … Read more

In C++11 what should happen first: raw string expansion or macros?

[Update: Adrian McCarthy comments below saying MSVC++ 2017 fixes this] GCC and clang are right, VC++ is wrong. 2.2 Phases of translation [lex.phases]: […] The source file is decomposed into preprocessing tokens (2.5) and sequences of white-space characters (including comments). Preprocessing directives are executed, […] And 2.5 Preprocessing tokens [lex.pptoken] lists string-literals amongst the tokens. … Read more

Can I redefine a C++ macro then define it back?

As greyfade pointed out, your ___T___ trick doesn’t work because the preprocessor is a pretty simple creature. An alternative approach is to use pragma directives: // juice includes here #pragma push_macro(“T”) #undef T // include boost headers here #pragma pop_macro(“T”) That should work in MSVC++ and GCC has added support for pop_macro and push_macro for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)