c-preprocessor

Passing preprocessor variable to nmake build environment

爱⌒轻易说出口 提交于 2019-12-23 14:49:48
问题 I am having issues with building driver using nmake on Win7 x64 build environment. I am defining a preprocessor variable and passing it over the command line using - build /nmake "USER_C_FLAGS=/DMyVersion=3" And the build log is - ... /DMyVersion=3 /typedil- /wd4603 /wd4627 .... So, I clearly see the variable as part of the compiler options. Now in a header fie, I do #define otherVersion 10 #ifdef MyVersion #undef otherVersion #define otherVersion MyVersion #endif #define FileVersion

Preprocessor directives

こ雲淡風輕ζ 提交于 2019-12-23 14:25:05
问题 When we see #include <iostream> , it is said to be a preprocessor directive . #include ---> directive And, I think: <iostream> ---> preprocessor But, what is meant by "preprocessor" and "directive"? 回答1: It may help to think of the relationship between a "directive" and being "given directions" (i.e. orders). "preprocessor directives" are directions to the preprocessor about changes it should make to the code before the later stages of compilation kick in. But, what's the preprocessor? Well,

Modular compile-time array expansion

谁说我不能喝 提交于 2019-12-23 14:13:07
问题 Let's say I'm in this sitation: main.c : #include <stdio.h> #include <stdlib.h> #include "header.h" int iCanProcess (char* gimmeSmthToProcess); int processingFunctionsCount = 0; int (*(*processingFunctions)) (char*) = NULL; int addProcessingFunction(int (*fct)(char*)) { processingFunctionsCount++; processingFunctions = realloc(processingFunctions, sizeof(int (*)(char*))*ProcessingFunctionsCount); processingFunctions[processingFunctionsCount-1] = fct; } int main(int argc, char *argv[]) { char*

Can intellisense be enabled in VS2008 within preprocessor directive blocks like #ifndef … #endif

混江龙づ霸主 提交于 2019-12-23 12:31:39
问题 While working within C++ libraries, I've noticed that I am not granted any intellisense while inside directive blocks like "#ifndef CLIENT_DLL ... #endif". This is obviously due to the fact that "CLIENT_DLL" has been defined. I realize that I can work around this by simply commenting out the directives. Are there any intellisense options that will enable intellisense regardless of directive evaluation? 回答1: By getting what you want, you would lose a lot. Visual C++ IntelliSense is based on a

macro if statement returns error: operator '&&' has no right operand

喜欢而已 提交于 2019-12-23 12:23:04
问题 I am compiling my code on many linux machines, on a specific machine, I receive the following error: error: operator '&&' has no right operand The macro code is: #if LINUX_VERSION_CODE == KERNEL_VERSION(3,12,49) && KERNEL_PATCH_LEVEL == 11 where LINUX_VERSION_CODE and KERNEL_VERSION are defined in linux sources and KERNEL_PATCH_LEVEL is defined in my Makefile KERNEL_PATCH_LEVEL :=$(word 1, $(subst ., ,$(word 2, $(subst -, ,$(KERNEL_HEADERS))))) If i change the code to 2 different lines, like

Way to omit undefined preprocessor branches by default with unifdef?

喜你入骨 提交于 2019-12-23 12:23:01
问题 I'm using a complicated C code that includes many, many compilation options. This makes the code very hard to read. I'd like to produce a copy of the code reflecting the way it's actually compiled. I've gotten pretty good results using the "unifdef" utility, which I didn't know about until recently. However, I'm puzzled why it's so hard to invoke, and am wondering if I'm missing something. Consider this example: #ifdef A printf("A\n"); #endif #ifdef B printf("B\n"); #endif If you invoke

What happens when a C preprocessor macro is defined twice?

我们两清 提交于 2019-12-23 12:19:46
问题 I define a macro twice as follows: #define a 2 #define a 3 I thought any occurrence of a in the code would be replaced by 2 , and when #define a 3 is encountered there are no more a s are available in the code to be replaced by 3 , so the 2 would take precedence. But when I executed it a was replaced by 3, why? 回答1: If you define a macro twice like that, the compiler should at least give you warning, if not an error. It is an error. §6.10.3/2 : An identifier currently defined as an object

What is the difference between #define and creating a normal type?

梦想的初衷 提交于 2019-12-23 12:14:03
问题 In C/C++, what is the difference between using #define [and #ifndef #endif ] to create values, when you can easily do it with an int or std::string [C++] too? #ifndef MYVAL #define MYVAL(500) #endif //C++ cout << MYVAL << endl; //C printf(MYVAL); //C++ int MYVAL = 500; cout << MYVAL << endl; //C int MYVAL = 500; printf(MYVAL); 回答1: Before I jump into history, here's a brief understanding of the difference between the two. Variables are, well, variables. They take up space in the compiled

Compiling previously preprocessed file changes output

旧巷老猫 提交于 2019-12-23 10:28:17
问题 I have a source file which I preprocess using the options -E and -P (using GCC 4.1.2 for a vxWorks-based embedded platform). All other options are the same as when I compile the file. These options are: -Wall -march=pentium -nostdinc -O0 -fno-builtin -fno-defer-pop -g -c -o as well as all include-paths. Now when I compile this preprocessed file, the resulting object-file is much smaller (about 30%) than when I compile the original directly. And when I then link the program, the linker

Test if a C macro's value is empty

允我心安 提交于 2019-12-23 10:15:54
问题 I need to write some code to verify that a macro is defined but empty (not having any values). The test does not need to be in compile time. I am attempting to write: #if (funcprototype == "") MY_WARN("funcprototype is empty"); #endif the code does not compile, as funcprototype expands to empty. 回答1: If a run-time check is okay, then you can test the length of the stringized replacement: #define REAL_STRINGIZE(x) #x #define STRINGIZE(x) REAL_STRINGIZE(x) if (STRINGIZE(funcprototype)[0] == '\0