c-preprocessor

Set preprocessor definitions from file content in Visual C++

柔情痞子 提交于 2019-12-20 04:53:28
问题 I have a file in my project which contains the project version number. I have to make the content of this file available as a preprocessor definition in my code. What I need is to somehow pass the value from the file to the compiler as a /D parameter. I tried to add the preprocessor definition VERSION=$(Version) and set the Version environment variable in a prebuild step, but I did not find a way to do the latter, so I got stuck. 回答1: As a workaround, a pre-build step could be created which

Set preprocessor definitions from file content in Visual C++

怎甘沉沦 提交于 2019-12-20 04:53:03
问题 I have a file in my project which contains the project version number. I have to make the content of this file available as a preprocessor definition in my code. What I need is to somehow pass the value from the file to the compiler as a /D parameter. I tried to add the preprocessor definition VERSION=$(Version) and set the Version environment variable in a prebuild step, but I did not find a way to do the latter, so I got stuck. 回答1: As a workaround, a pre-build step could be created which

##__VA_ARGS__ not swallowing comma when zero args under C99

十年热恋 提交于 2019-12-20 04:13:30
问题 I'd like to use a macro like the following: #define x(...) y(a,##__VA_ARGS__,b) To expand like so: x(); -> y(a,b); x(1); -> y(a,1,b); With -std=gnu99 , it works perfectly. With -std=c99 however, it looks like this: x(); -> y(a,,b); x(1); -> y(a,1,b); The ## is making no difference – it's not swallowing the comma. In other usages under C99, e.g. #define x(a,...) y(a,##__VA_ARGS__) , comma-swallowing works fine. What can I do, if anything, to get the desired comma-swallowing behaviour under

C++ classes with members referencing each other

十年热恋 提交于 2019-12-20 03:31:46
问题 I'm trying to write 2 classes with members that reference each other. I'm not sure if I'm doing something wrong or it's just not possible. Can anyone help me out here... Source.cpp #include "Headers.h" using namespace std; void main() { Network* network = new Network(); system("pause"); return; } Headers.h #ifndef Headers_h #define Headers_h #include <iostream> #include <vector> #include "Network.h" #include "Router.h" #endif Network.h #include "Headers.h" class Network { protected: vector

Real-world advantage of namespace aliases vs defines [closed]

荒凉一梦 提交于 2019-12-20 03:22:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . EDIT: I'm planing to refactor some code, and replace the define with a namespace alias. I can't do this though just because "macros

Is there a way to control macro expansion order

半腔热情 提交于 2019-12-20 02:36:09
问题 I am hoping that someone may have an idea on how to control/specify the order of macro expansion. Here is the context: // 32 bit increments, processor has registers for set, clear and invert #define CLR_OFF 1 #define SET_OFF 2 #define INV_OFF 3 #define SET(reg,bits) *((volatile unsigned long*)(& reg+SET_OFF)) = bits //Now if I use this I can do it quite nicely with #define STATUS_LED 0x0040; SET(LATB, STATUS_LED); // LATB is port of the LED. I've actually had to move hardware around quite a

How to force const propagation through an inline function?

不羁岁月 提交于 2019-12-20 02:35:39
问题 I'm trying to coerce the pre-processor to perform some math for me so a constant gets propagated into inline assembly. Here's the reduced case: inline unsigned int RotateRight(unsigned char value, unsigned int amount) { COMPILE_ASSERT(((unsigned char)(amount%32)) < 32); __asm__ ("rorb %1, %0" : "+mq" (value) : "I" ((unsigned char)(amount%32))); return value; } The code above relies upon CPU specific functionality, and I'm OK with it (its actually a template specialization on x86/x64 Linux

How to force const propagation through an inline function?

為{幸葍}努か 提交于 2019-12-20 02:35:07
问题 I'm trying to coerce the pre-processor to perform some math for me so a constant gets propagated into inline assembly. Here's the reduced case: inline unsigned int RotateRight(unsigned char value, unsigned int amount) { COMPILE_ASSERT(((unsigned char)(amount%32)) < 32); __asm__ ("rorb %1, %0" : "+mq" (value) : "I" ((unsigned char)(amount%32))); return value; } The code above relies upon CPU specific functionality, and I'm OK with it (its actually a template specialization on x86/x64 Linux

How can I provide template specializations for typedefs of the same type?

巧了我就是萌 提交于 2019-12-20 01:09:38
问题 A 3rd party SDK defines several typedefs, e.g.: typedef unsigned char SDK_BYTE typedef double SDK_DOUBLE typedef unsigned char SDK_BOOLEAN It also defines a variant type SdkVariant: class SdkVariant { public: enum SdkType { SdkByte, SdkDouble, SdkBoolean }; bool toByte(SDK_BYTE&); bool toDouble(SDK_DOUBLE&); bool toBool(SDK_BOOLEAN&); SdkType type(); }; Retrieving a value from such a variant looks like this (presuming, we know the type of the contained value): SdkVariant variant(foobar());

CPP/GPP in Fortran variadic macro (plus Fortran // concatenation)

筅森魡賤 提交于 2019-12-20 01:04:54
问题 I'm trying to compile a huge, world-renowned numerical weather prediction code - written mostly in Fortran 90 - that uses cpp extensively, and successfully, with PGI, Intel and gfortran. Now, I've inherited a version where experts have added several hundred cases of variadic macros. They use Intel and fpp , which is presumably a little more Fortran-centric, and can get it all to work. I need to use gfortran, and have not been able to get cpp to work on this code with its new additions. A