c-preprocessor

Is this expression correct in C preprocessor [closed]

蓝咒 提交于 2019-12-13 09:55:37
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I want to do the following arithmetic functions in a C pre-processor include statement when I send in the variable x . #define calc_addr_data_reg (x) ( base_offset + ((x/7) * 0x20) + data_reg_offset) How would I

Few questions about the C++ preprocessor:

心已入冬 提交于 2019-12-13 09:48:45
问题 A few questions about the C++ preprocessor: how to make the preprocessor go to a new line into the preprocessoring code? how to make the preprocessor insert a tab character or multiple spaces into the preprocessoring code? how to make the preprocessor insert comments into the preprocessoring code? 回答1: 1) use the backslash, as Tim pointed out 2) I don't think you can 3) #define COMMENT /##/ this is a comment #define CPPCOMMENT(c) /##/ c #define CCOMMENT(c) /##* c *##/ COMMENT CPPCOMMENT(This

Replace cout<<“string” with cout<<“string”<<endl in cpp

故事扮演 提交于 2019-12-13 09:02:45
问题 I want to replace each cout occurring in a program with same but concatenated with endl . I'm trying to use macros for this but unable to figure that out how to do that. Please help! Is there a way to get complete line written in program and just concat << endl with it? Note if endl is already written by programmer, no endl will be concatenated. If any other better method possible, please suggest. 回答1: Unfortunately, this is possible. But in no sense can I condone it. #include <iostream>

Using macros on functions in an array to make gtest typed-parameterized tests more succinct

北城余情 提交于 2019-12-13 07:51:04
问题 Right now, IMO, Google typed-parameterized tests are annoying. You have to do: template <typename fixtureType> class testFixtureOld : public ::testing::Test { }; // Tell google test that we want to test this fixture TYPED_TEST_CASE_P(testFixtureOld); // Create the tests using this fixture TYPED_TEST_P(testFixtureOld, OIS1Old) { TypeParam n = 0; EXPECT_EQ(n, 0); } TYPED_TEST_P(testFixtureOld, OIS2Old) { TypeParam n = 0; EXPECT_EQ(n, 0); } // Register the tests we just made REGISTER_TYPED_TEST

Is it legal to re-declare a member class after defining it?

白昼怎懂夜的黑 提交于 2019-12-13 05:46:30
问题 I have a problem with compiling boost.bimap library. My test program is a blank main function and only one include directive(like #include <boost/bimap.hpp> ). After some investigations I found out that preprocessor had made some interesting constructions from header file like: struct A { struct B{}; struct B; }; I don't know if this is correct or not, but gcc accepts it while clang and icc don't. Who is right and what can I do to compile programs with bimap library? Unfortunately, I can't

C Preprocessor Macros - conditionals based upon argument concatenation

牧云@^-^@ 提交于 2019-12-13 04:35:00
问题 I need help with macros, please! Suppose I’ve got the following constants defined #define foo_tacos_tuesday 1 #define foo_tacos 1 #define foo_nachos_wednesday 2 #define foo_nachos 3 I’d like to write a macro that does the following #define MyFancyMacro( arg1, arg2 ) \ #if ( foo_ ## arg1 ## _ ## arg2 != foo_ ## arg1 ) \ foo_ ## arg1 ## _ ## arg2, foo_ ## arg1, So I can set up a mapping table that only maps the mismatching values: static const int mappingTable[] = { MyFancyMacro(tacos, tuesday)

Highlighting #defined value in VIM

China☆狼群 提交于 2019-12-13 03:56:19
问题 I have XYZ highlighted in the header file where I have defined XYZ. However at the point of where it is used, XYZ is not highlighted. How would I fix this ? I have attached two screen shots (see TH_SYN in the code) to clarify my question- link text Any pointers are welcome. 回答1: I have done a very crude way of doing this for Java constants (static finals), based on the fact that all constants, are all caps with underbars. Almost no other identifiers match that criteria. So a very simple, and

#define many times without #undef,is it legal?

旧时模样 提交于 2019-12-13 02:55:21
问题 For example, I define AA for three times, is it legal?: #include<stdio.h> #define AA 10 #define AA 20 #define AA 30 int main() { printf("AA"); } 回答1: This is not legal in both C and C++. Quotes from draft C standard N1570: 6.10.3 Macro replacement Constraints 1 Tw o replacement lists are identical if and only if the preprocessing tokens in both have the same number, ordering, spelling, and white-space separation, where all white-space separations are considered identical. 2 An identifier

Unexpected Behaviour of GCC and VC++ Preprocessor

一世执手 提交于 2019-12-13 02:22:25
问题 I am trying to understand the C++ standard preprocessor requirement. A little bit tricky example I created has surprising results in GCC and VC++2010: #define a(x,y) x##y #define tzsW kka a(t,zs )W GCC yields: tzs W Note the extra space added before W. VC++2010 yields: tzsW Note there is no space added before W but the identifier is not further expanded. I scanned through the C++03 standard and cannot find anything saying we should prevent a new identifier ( tzsW ) from being created as in

How to use switch statement inside a macro in C?

霸气de小男生 提交于 2019-12-13 02:21:20
问题 I want to use switch statement inside a macro in C. I have the following code segment: enum errors { ERROR_NO_MEMORY, ERROR_INVALID_INDEX, ERROR_INVALID_VALUE }; #define MSG_NO_MEMORY "could not allocate memory" #define MSG_INVALID_INDEX "index out of bounds" #define MSG_INVALID_VALUE "invalid value passed as input" #define MESSAGE(err) \ switch (err) { \ case ERROR_NO_MEMORY: \ return MSG_NO_MEMORY; \ case ERROR_INVALID_INDEX: \ return MSG_INVALID_INDEX; \ case ERROR_INVALID_VALUE: \ return