preprocessor

undef'ing a function-like macro

Hello In the C/C++ there are 2 types of macro: #define ABC /* usual */ und #define FUNC(a) /*function-like*/ But how can I undefine them? Update: So there is no difference between undefing "constant-like macro" and "function-like macro" ? ...

AS3 Embedding assets - "Warning: Failed to parse corrupt data"

I've got an AS3 project where I'm trying to compile in several images, a soundtrack, and a video via [Embed] metadata. It's a product requirement that these be embedded, so network transfer is not an option. I'm getting some really strange behavior - a sort of intermittent corruption of the compiled-in data. Sometimes after the proje...

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

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 opti...

Multiple preprocessor directives on one line in C++

A hypothetical question: Is it possible to have a C++ program, which includes preprocessor directives, entirely on one line. Such a line would look like this: #define foo #ifdef foo #define bar #endif What are the semantics of such a line? Further, are there any combinations of directives which are impossible to construct on one li...

Can I add numbers with the C/C++ preprocessor?

For some base. Base 1 even. Some sort of complex substitution -ing. Also, and of course, doing this is not a good idea in real life production code. I just asked out of curiosity. ...

Custom gcc preprocessor

Folks, could you please give me an example of writing a custom gcc preprocessor? My goal is to replace SID("foo") alike macros with appropriate CRC32 computed values. For any other macro I'd like to use the standard cpp preprocessor. It looks like it's possible to achieve this goal using -no-integrated-cpp -B options, however I can't ...

Prepocessor checking defined

Hello, I can check predefined value like: #ifdef SOME_VAR // Do something #elif // Do something 2 #endif If I have to check 2 values instead of 1. Are there any operator: #ifdef SOME_VAR and SOME_VAR2 // ... #endif Or I have to write: #ifdef SOME_VAR #ifdef SOME_VAR2 // At least! Do something #endif #endif ...

Are Preprocessor Definitions compiled into a library?

Hi, First off, if this question has already been asked or way too naive, I apologize. I searched for it and could not find it. Are they (preprocessor definitions) compiled into a static/dynamic library? For example, the FBX SDK needs KFBX_DLLINFO. A library that makes use of FBX SDK must include that. Now the client application, as fa...

m4 does not obey expansion?

Hi, I use m4 for a little text preprocessing here, and it behaves in a way I don't understand. This is the portion in question: ifdef(`TEST', define(`O_EXT', `.obj'), define(`O_EXT', `.o')) This macro will always be expanded to .o, regardless whether TEST is defined (m4 -DTEST) or not. What am I doing wrong? ...

Only run C preprocessor in cmake?

I'm trying to use cmake to simplify distributing my OpenCL program. I have a kernel file which includes several headers and other source files, and I want to have a single self contained executable. My plan is to have cmake run the C preprocessor on the kernel source, turning the cl file and its includes into a single unit which is easi...

Variadic macros with zero arguments, and commas

Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero arguments it produces bad code since the compiler expects an identifier after the comma. Actually, VC's preprocessor is smart enough to remove the comma, but GCC's isn't. Since macros can't be overloaded, it seems like it takes a se...

Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile

I have a project in c++ that I would like to view the preprocessor output to see what some #defines and macros would look like. I tried the /p switch to turn on the preprocess to a file option to the compiler (it turns off full compilation and only runs the preprocessor) but my project now refuses to compile and shows a long list of err...

C preprocessor magic

I'm trying to use preprocessor tricks to declare a magic variable. Something like this: DECLARE(x) should expand to int _DECLARED_VARIABLE_x_LINE_12 if the declaration was on line 12 of the input source. I was trying to use the ## token-pasting command and the __LINE__ macro, but I either get an uninterpreted "__LINE__" in there or...

using the C preprocessor to effectively rename variables

I'm writing a few very tight loops and the outermost loop will run for over a month. It's my understanding that the less local variables a function has, the better the compiler can optimize it. In one of the loops, I need a few flags, only one of which is used at a time. If you were the proverbial homicidal maniac that knows where I liv...

Evaluate macro parameter once only

In the following code, whatever is passed as retval is evaluated as given for every use of that token. #define _CPFS_RETURN(commit, retval) do { \ util_cpfs_exit(commit); \ return retval; \ } while (false) #define CPFS_RETURN_BOOL(retval) do { \ _CPFS_RETURN(retval, retval); \ } while (false) For examp...

Why use #if 0 for block commenting out?

Reverse engineering code and I'm kind of appalled at the style, but I wanted to make sure there's no good reason for doing these things.... Is it just me or is this a horrible coding style if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name); else sprintf(username,"%d",user_id); And why wrap code not intended for compilation in an #if...

C Macro Token Concatenation involving a variable - is it possible?

Hello, I'm trying to define a macro to generate a token name, containing a variable. Basically, what I'm trying is this: #define GLUER(x,y,z) x##y##z #define PxDIR(x) GLUER(P,x,DIR) int main() { int port; port = 2; PxDIR(port) |= 0x01; } I'm hoping to generate the token P2DIR in the above statement, but according to my compile...

append items to an array with a macro, in C

Hi, i have an array (C language) that should be initialized at compile time. For example: DECLARE_CMD(f1, arg); DECLARE_CMD(f2, arg); The DECLARE_CMD is called from multiple files. I want this to be preprocessed in. my_func_type my_funcs [] = { &f1, &f2 } It is possible, with a macro, to append items to an static array? I...

Possible to #if or #ifdef based on preprocessor-generated "thing"

I'm trying to engage in some C-preprocessor-only templating efforts in order to type-specialize some code. I've tried to boil it down a bit, so this example seems trivial and pointless, but the real challenge is getting the "include" blocking. Say I have a "template" file, that gets #included from other source files that define T_ELEME...

Explain C code snippet: preprocessor + printf = ???

The output for this code snippet is %s is a string is a string. Please explain. #include <stdio.h> #define scanf "%s is a string" int main() { printf(scanf, scanf); } ...