c-preprocessor

BOOST_PP expand sequence in the empty sequence case

蹲街弑〆低调 提交于 2021-02-08 02:57:29
问题 Using BOOST_PP I can expand a macro into multiple comma separated values with an additional token, as can be seen in the below code. However, it doesn't work in the no-argument case. #define BOOST_PP_VARIADICS #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/variadic/to_seq.hpp> #define ADD_TOKEN(r, token, i, e) \ BOOST_PP_COMMA_IF(i) token(e) #define WRAP(...) \ BOOST_PP_SEQ_FOR_EACH_I(ADD_TOKEN, decltype,

C Preprocessor: Stringify int with leading zeros?

旧时模样 提交于 2021-02-07 18:27:27
问题 I've seen this topic which describes the "stringify" operation by doing: #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #define MAJOR_VER 2 #define MINOR_VER 6 #define MY_FILE "/home/user/.myapp" STR(MAJOR_VER) STR(MINOR_VER) Is it possible to stringify with leading zeros? Let's say my MAJOR_REV needs to be two characters "02" in this case and MINOR_REV 4 characters "0006" If I do: #define MAJOR_VER 02 #define MINOR_VER 0006 The values will be treated as octal elsewhere in the

C Preprocessor: Stringify int with leading zeros?

…衆ロ難τιáo~ 提交于 2021-02-07 18:27:26
问题 I've seen this topic which describes the "stringify" operation by doing: #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #define MAJOR_VER 2 #define MINOR_VER 6 #define MY_FILE "/home/user/.myapp" STR(MAJOR_VER) STR(MINOR_VER) Is it possible to stringify with leading zeros? Let's say my MAJOR_REV needs to be two characters "02" in this case and MINOR_REV 4 characters "0006" If I do: #define MAJOR_VER 02 #define MINOR_VER 0006 The values will be treated as octal elsewhere in the

C++ preprocessor token pasting for namespace qualification

你离开我真会死。 提交于 2021-02-07 06:48:19
问题 I am having trouble with the preprocessor token pasting operator in gcc 4.7.1 (std=c++11). Namely, consider the following code: // Create a name for a global map (this works) #define GLOBAL_MAP(name) g_map_ ## name // This works fine // Now, namespace qualify this map (this fails to compile when used) #define NS_QUAL_GLOBAL_MAP(name) SomeNamespace:: ## GLOBAL_MAP(name) Usage scenarios - first the map definitions: std::map<std::string,std::string> GLOBAL_MAP(my_map); namespace SomeNamespace {

C++ preprocessor token pasting for namespace qualification

落花浮王杯 提交于 2021-02-07 06:48:19
问题 I am having trouble with the preprocessor token pasting operator in gcc 4.7.1 (std=c++11). Namely, consider the following code: // Create a name for a global map (this works) #define GLOBAL_MAP(name) g_map_ ## name // This works fine // Now, namespace qualify this map (this fails to compile when used) #define NS_QUAL_GLOBAL_MAP(name) SomeNamespace:: ## GLOBAL_MAP(name) Usage scenarios - first the map definitions: std::map<std::string,std::string> GLOBAL_MAP(my_map); namespace SomeNamespace {

Extracting preprocessor symbols from source

為{幸葍}努か 提交于 2021-02-06 15:23:02
问题 I'm looking for a way to extract all preprocessor symbols used in my code. As an example, if my code looks like this: #ifdef FOO #endif #if ( BAR == 1 && \ defined (Z) ) #endif I'd like to get the list [FOO,BAR,Z] as the output. I found some posts suggesting gcc -E -dM , but this displays all symbols that the preprocessor would apply to the code. What I want, in contrast, is a list of all symbols actually used in the code . Any suggestions? 回答1: That's quite simple. You have just to parse the

Extracting preprocessor symbols from source

为君一笑 提交于 2021-02-06 15:22:50
问题 I'm looking for a way to extract all preprocessor symbols used in my code. As an example, if my code looks like this: #ifdef FOO #endif #if ( BAR == 1 && \ defined (Z) ) #endif I'd like to get the list [FOO,BAR,Z] as the output. I found some posts suggesting gcc -E -dM , but this displays all symbols that the preprocessor would apply to the code. What I want, in contrast, is a list of all symbols actually used in the code . Any suggestions? 回答1: That's quite simple. You have just to parse the

Options for defining preprocessor macros with parameters for entire project or solution in Visual Studio

Deadly 提交于 2021-02-04 18:30:08
问题 I want some macros having parameters to be available in all files in a project or better a complete solution. In VS2010, if I add them to the Preprocessor Definitions in properties->Configuration Properties->C/C++->Preprocessor using something like SQUARE(x)=((x)*(x));CUBE(x)=(SQUARE(x)*x); the macro definitions are not used by the compiler. However the approach may be close since IntelliSense provides the correct definitions when I hover over the macros in the source code. Is there a way to