preprocessor

Is there a way to control macro expansion order.

Howdy! 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*)( SET(LATB, STATUS_LED); // LATB...

How can I determine the relationship of C integer type MIN/MAXes in the preprocessor?

I’m trying to determine the relationship of a given compiler’s integer types’ sizes using the preprocessor. My requirement is that I have two types, one of which is unsigned, and one of which is a signed type capable of storing every positive number that said unsigned type can store. i.e. I have to ensure that my ll_ssize type can store ...

GCC preprocessor question

Is it possible to instruct the GCC preprocessor not to remove comments when processing files? ...

Why is post-compilation code injection a better idea than pre-compilation code injection?

So we all know that C# doesn't have a C-like macro pre-processor (and there's a good thread on why here). But now that AOP is gaining traction, it seems like we're starting to do stuff with post-processors that we used to do with pre-processors (bear in mind that I am only getting my feet wet with PostSharp so am perhaps off base). I am...

What's the meaning of #line in C language?

What's the meaning of #line in C language? Where would it be used? ...

Variable definition in header files

My very basic knowledge of C and compilation process has gone rusty lately. I was trying to figure out answer to the following question but I could not connect compilation, link and pre-processing phase basics. A quick search on the Google did not help much either. So, I decided to come to the ultimate source of knowledge :) I know: V...

How to generate an error and warning in C preprocessor?

As the title. I have a program must be compiled only in DEBUG mode. (testing purpose) So I want to prevent compilation in RELEASE mode by this way. ...

Boost Preprocessor library for generating a set of types based on a list of basic types e.g. PointI32, PointF32 etc. in C++/CLI

Hi, I am trying to figure out how to use the Boost.Preprocessor library http://www.boost.org/doc/libs/release/libs/preprocessor to unfold a "generic" type for different specific types. Below I will ask this for a simple point class example. Given: struct Point##TYPE_SUFFIX_NAME { TYPE X; TYPE Y; // Other code }; I want to...

GCC dump preprocessor defines

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

#if 0 as a define

I need a way to define a FLAGS_IF macro (or equivalent) such that FLAGS_IF(expression) <block_of_code> FLAGS_ENDIF when compiling in debug (e.g. with a specific compiler switch) compiles to if (MyFunction(expression)) { <block_of_code> } whereas in release does not result in any instruction, just as it was like this #if 0 ...

How is the @encode compiler directive implemented in Objective-C?

Can anyone explain how @encode works to extract the datatype elements present in a given object, struct, or datatype into a type definition to be used as a class descriptor for instantiation? Or maybe a pointer to some resources for learning about the implementation of new preprocessor directives? ...

export C #defines as shell variables

In my project, a number of paths to various directories, files and other components of the system are stored as #defines in a filenames.h, a file included by all that need them. It works well for all the various binaries generated by compilation, but the project also includes a few shell scripts that use the same paths. Currently this me...

Why would somebody use an if 1 c preprocessor directive

I am looking through some C source code and I don't understand the following part #if 1 typedef unsigned short PronId; /* uniquely identifies (word,pron) pair, i.e. homophones have different Ids */ typedef unsigned short LMId; #define LM_NGRAM_INT #else typedef unsigned int LMId; typedef u...

How to make G++ preprocessor output a newline in a macro?

Hello, Is there a way in gcc/g++ 4.* to write a macro that expands into several lines? The following code: #define A X \ Y Expands into X Y I need a macro expanding into X Y ...

Preprocessor to add functionality to Windows's CMD?

I need to do a fair bit of scripting in my job as a SQL Server DBA. Sometimes, I need to deploy a fix script to a very restricted environment, where the only option for scripting may be DOS Batch. In one such environment, even VBScript/WSH isn't a possibility, let alone PowerShell. Anyone who has written enough batch files on DOS and Win...

Can I see defined macros during compilation of a C code?

I have a piece of code which compiles without problems with x86 gcc 4.4.1 but fails with blackfin gcc 4.1.2 with many "expected unqualified-id before numeric constant" errors. I see that there are some variable names that clash with some predefined macros. Is it possible to see defined macros at a certain line of a cpp file? ...

how do I use c preprocessor to make a substitution with an environment variable

In the code below, I would like the value of THE_VERSION_STRING to be taken from the value of the environment variable MY_VERSION at compile time namespace myPluginStrings { const char* pluginVendor = "me"; const char* pluginRequires = THE_VERSION_STRING; }; So that if I type: export MY_VERSION="2010.4" pluginRequires will be se...

C Preprocessor adds comments of its own

Hi, If any, what are the (obviously ignored by GCC) comments below called? How do I get rid of them? Here: eisbaw@leno:~/GCC$ cpp < /dev/null # 1 "<stdin>" # 1 "<built-in>" # 1 "<command-line>" # 1 "<stdin>" eisbaw@leno:~/GCC$ ...

Is there a better alternative to preprocessor redirection for runtime tracking of an external API?

OK, I have sort of a tricky problem I'm attempting to solve. First of all, an overview: I have an external API not under my control, which is used by a massive amount of legacy code. There are several classes of bugs in the legacy code that could potentially be detected at run-time, if only the external API was written to track its ow...

Why can't I use sizeof() in a #if?

I have this: #if sizeof(int) #error Can't use sizeof in a #if #endif I get this compiler error: missing binary operator before token "(" Why can't I use the sizeof operator here? ...