c-preprocessor

Declare a variable and add it to an array at compile time

别说谁变了你拦得住时间么 提交于 2021-01-28 03:21:31
问题 I'd like to get a C macro (or several) that could serve two purposes: Declare a const variable. Add that variable to an array. I.e , if I have this typedef struct { int port; int pin; } pin_t; A macro like this #define DEFINE_PIN(name, port, num) should expand to something like this #define NAME port, num const pin_t[] = { {NAME} }; And each definition should append the new defined variable to the array. I know that a #define cannot expand to #define s but is just an illustration. What I want

What does “macro annotations embedding in comments” mean in mcpp?

断了今生、忘了曾经 提交于 2021-01-27 13:15:54
问题 In mcpp.exe --help Options available with only -@std (default) option: -@compat Expand recursive macro more than Standard. -3 Enable trigraphs. -K **Output macro annotations embedding in comments.** So, what does 'macro annotation in comments' mean? http://mcpp.sourceforge.net/ 回答1: From the mcpp-summary-272.pdf file available at SourceForge (link in question): Also mcpp has a mode to output macro informations embedded in comments. This mode allows you to know macro calls and their locations

Macro Operator List

99封情书 提交于 2021-01-27 11:28:10
问题 I know about Macro's Stringizing operator ( # ) and I recently learned about the ( ## ) Concatenation operator: Preprocessor Stringizing Operator with String Literal Prefixes Are there any other macro operators that are available to me? I know that Boost has a pretty extensive suite that they've put together, however for the purposes of this question I'm just asking about Macro operator support defined by the standard. 回答1: As is mentioned by Cyber's comment the Sringizing ( # ) and

Macro Operator List

拈花ヽ惹草 提交于 2021-01-27 11:26:30
问题 I know about Macro's Stringizing operator ( # ) and I recently learned about the ( ## ) Concatenation operator: Preprocessor Stringizing Operator with String Literal Prefixes Are there any other macro operators that are available to me? I know that Boost has a pretty extensive suite that they've put together, however for the purposes of this question I'm just asking about Macro operator support defined by the standard. 回答1: As is mentioned by Cyber's comment the Sringizing ( # ) and

Macro Operator List

蹲街弑〆低调 提交于 2021-01-27 11:25:24
问题 I know about Macro's Stringizing operator ( # ) and I recently learned about the ( ## ) Concatenation operator: Preprocessor Stringizing Operator with String Literal Prefixes Are there any other macro operators that are available to me? I know that Boost has a pretty extensive suite that they've put together, however for the purposes of this question I'm just asking about Macro operator support defined by the standard. 回答1: As is mentioned by Cyber's comment the Sringizing ( # ) and

What preprocessor symbols does Coverity define for a build using 'cov-build'?

萝らか妹 提交于 2021-01-27 06:26:12
问题 We use Coverity's Scan Build service for free and open source projects. I am working through two Coverity findings on tainted parameters ( TAINTED_SCALAR ). The taint is a false positive, so I am trying to instrument the code with Coverity's __coverity_tainted_data_sanitize__ to clear the issue. I want to guard the code that needs to use __coverity_tainted_data_sanitize__ because the function is only used with analysis builds using Coverity's cov-build tool. That is, I want to do something

How do I #define multiple values C / C++

大城市里の小女人 提交于 2021-01-25 20:53:30
问题 How would I define multiple values of the same type in an array using #define ? For instance, I would like #define DIGIT 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 #define QUOTE 0x22 | 0x27 ETC... 回答1: How would I define multiple values of the same type in an array using #define ? For instance, I would like #define DIGIT 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 #define QUOTE 0x22 | 0x27 Well, the term array in C and C++ refers to a number of

How do I #define multiple values C / C++

╄→尐↘猪︶ㄣ 提交于 2021-01-25 20:41:26
问题 How would I define multiple values of the same type in an array using #define ? For instance, I would like #define DIGIT 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 #define QUOTE 0x22 | 0x27 ETC... 回答1: How would I define multiple values of the same type in an array using #define ? For instance, I would like #define DIGIT 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 #define QUOTE 0x22 | 0x27 Well, the term array in C and C++ refers to a number of

If-directive macro comparison

陌路散爱 提交于 2021-01-20 22:13:13
问题 Why is the #if condition in the following code fulfilled: #include <iostream> #define VALUE foo int main() { #if VALUE == bar std::cout << "WORKS!" << std::endl; #endif // VALUE } 回答1: The page on cppreference.com states: After all macro expansion and evaluation of defined and __has_include (since C++17) expressions, any identifier which is not a boolean literal is replaced with the number ​0​ (this includes identifiers that are lexically keywords, but not alternative tokens like and). So

If-directive macro comparison

杀马特。学长 韩版系。学妹 提交于 2021-01-20 22:12:57
问题 Why is the #if condition in the following code fulfilled: #include <iostream> #define VALUE foo int main() { #if VALUE == bar std::cout << "WORKS!" << std::endl; #endif // VALUE } 回答1: The page on cppreference.com states: After all macro expansion and evaluation of defined and __has_include (since C++17) expressions, any identifier which is not a boolean literal is replaced with the number ​0​ (this includes identifiers that are lexically keywords, but not alternative tokens like and). So