“No newline at end of file” compiler warning
What is the reason for the following warning in some C++ compilers? No newline at end of file Why should I have an empty line at the end of a source/header file? 11 Answers 11
What is the reason for the following warning in some C++ compilers? No newline at end of file Why should I have an empty line at the end of a source/header file? 11 Answers 11
How can I add a ‘or’ condition in #ifdef ? I have tried: #ifdef CONDITION1 || CONDITION2 #endif This does not work. 3 Answers 3
I want to write a macro in C that accepts any number of parameters, not a specific number example: #define macro( X ) something_complicated( whatever( X ) ) where X is any number of parameters I need this because whatever is overloaded and can be called with 2 or 4 parameters. I tried defining the … Read more
Let’s say I have a source file with many preprocessor directives. Is it possible to see how it looks after the preprocessor is done with it? 10 Answers 10
I have two macros FOO2 and FOO3: #define FOO2(x,y) … #define FOO3(x,y,z) … I want to define a new macro FOO as follows: #define FOO(x,y) FOO2(x,y) #define FOO(x,y,z) FOO3(x,y,z) But this doesn’t work because macros do not overload on number of arguments. Without modifying FOO2 and FOO3, is there some way to define a macro … Read more
Trying to create a macro which can be used for print debug messages when DEBUG is defined, like the following pseudo code: #define DEBUG 1 #define debug_print(args …) if (DEBUG) fprintf(stderr, args) How is this accomplished with a macro? 14 Answers 14
I need my code to do different things based on the operating system on which it gets compiled. I’m looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is there a better way to do the same thing? 16 Answers … Read more
I was wondering if someone could explain to me what the #pragma pack preprocessor statement does, and more importantly, why one would want to use it. I checked out the MSDN page, which offered some insight, but I was hoping to hear more from people with experience. I’ve seen it in code before, though I … Read more
Is there a way for gcc/g++ to dump its preprocessor defines from the command line? I mean things like __GNUC__, __STDC__, and so on. 6 Answers 6
This question already has answers here: How do I check OS with a preprocessor directive? (16 answers) Closed 2 years ago. The community reviewed whether to reopen this question 3 months ago and left it closed: Original close reason(s) were not resolved If there’s some cross-platform C/C++ code that should be compiled on Mac OS … Read more