preprocessor

C++ throwing compilation error on sizeof() comparison in preprocessor #if

I have this which does not compile with the error "fatal error C1017: invalid integer constant expression" from visual studio. How would I do this? template <class B> A *Create() { #if sizeof(B) > sizeof(A) #error sizeof(B) > sizeof(A)! #endif ... } ...

Removing macro in legacy code

I have a lot of legacy code using macro of the form: #define FXX(x) pField->GetValue(x) The macro forces variable pField be in the scope: ..... FIELD *pField = .... ..... int i = FXX(3); int j = FXX(5); Is there way to replace the macro, without touching user code? Since FXX(x) has a function invocation style, I thought about inl...

See what the preprocessor is doing

Is there anyway to see what you code looks like after the preprocessor has done all the substitutions? ...

macros as arguments to preprocessor directives

Being faced with the question wether its possible to choose #includes in the preprocessor i immediately thought not possible. .. Only to later find out that it is indeed possible and you only need to watch out for argument expansions (which e.g. Boost.Preprocessor can take care of). While i'd avoid actually doing that for includes if po...

Visual Studio 2008 Preprocessor wierdness

We have set-up a simple versioning system for our builds to ensure the built files always indicate whether they are Beta Debug or Beta Release builds I moved the file version info to to myapp.rc2 and created version.h // version.h // _DEBUG is defined by VS #define _BETA #ifdef _BETA #define FILE_DESC1 _T("BET...

Testrun preprocessor statement

Is there a way to set a constant depending on whether unit tests are run? The problem with the unit test framework is de way it deals with dependencies; it will copy files but it does not seem to respect the directory structure. As a solution, I'm checking whether the DEBUG constant is set when looking for files to load but this raises p...

Check whether function is declared with C preprocessor?

Is it possible to tell the C preprocessor to check whether a function (not a macro) is declared? I tried the following, but it doesn't appear to work: #include <stdio.h> int main(void) { #if defined(printf) printf("You support printf!\n"); #else puts("Either you don't support printf, or this test doesn't work."); #endif ret...

Convert string from __DATE__ into a time_t

I'm trying to convert the string produced from the __DATE__ macro into a time_t. I don't need a full-blown date/time parser, something that only handles the format of the __DATE__ macro would be great. A preprocessor method would be nifty, but a function would work just as well. If it's relevant, I'm using MSVC. ...

C Programming: Preprocessor, macros as tokens

Hi, I'm trying to do something that is conceptually similar to this, but can't seem to get it to work (error shown at end) any ideas? #include <stdio.h> int main( int argc , char const *argv[] ) { int abc_def_ghi = 42; #define SUFFIX ghi #define VAR(prefix) prefix##_def_##SUFFIX printf( "%d\n" , VAR(abc) ); return 0; } // un...

C Programming: Preprocessor, include files from macro

If I could find a way to do something similar to this, I could cut out hundreds of lines of code in my application, and dramatically increase maintainability. Anyone have any ideas? #include <stdio.h> int main( ) { #define include_all_files(root) \ #include #root "1.h" \ #include #root "2.h" \ ...

C - the most useful user-made C-macros (in GCC, also C99) ?

What C-macros is in your opinion is the most useful? I have found the following one, which I use to do vector arithmetics in C: #define v3_op_v3(x, op, y, z) {z[0]=x[0] op y[0]; \ z[1]=x[1] op y[1]; \ z[2]=x[2] op y[2];} It works like that: v3_op_v3(vectorA, +, vectorB, ve...

Wix - how to handle project references when using heat's output with candle?

Hi, I'm trying to use heat on a web .csproj, and then use candle on the output. So far, I've done: heat project "StatusReport Web.csproj" -pog:Binaries pog:Content -ag -out StatusReport.wxs And then: candle StatusReport.wxs However, upon the latter, I get: Error CNDL0150: Undefined preprocessor variable '$(var.StatusReport Web.Ta...

C++ Preprocessor metaprogramming: obtaining an unique value?

Hi, I'm exploiting the behavior of the constructors of C++ global variables to run code at startup in a simple manner. It's a very easy concept but a little difficult to explain so let me just paste the code: struct _LuaVariableRegistration { template<class T> _LuaVariableRegistration(const char* lua_name, const T& c_name) { ...

how do I add preprocessor #define in devenv command line?

Is there a way to add extra preprocessor #define in devenv command line? ...

Why should one bother with preprocessor directives?

This question may seem rather basic, but coming from an engineering (non computer-science) background, I was unsure about what the snippets of '#'s were in some C++ code. A quick search led me to the concise, well-explained cplusplus tutorial page on preprocessor directives. But why bother with the concept of preprocessor directives at...

Can I redefine a c++ macro for a few includes and then define it back?

I am using both the JUCE Library and a number of Boost headers in my code. Juce defines "T" as a macro (groan), and Boost often uses "T" in it's template definitions. The result is that if you somehow include the JUCE headers before the Boost headers the preposser expands the JUCE macro in the Boost code, and then the compiler gets hop...

#DEBUG Preprocessor statements in ASPX page

I'm trying to use a preprocessor directive in an ASPX page, but the page doesn't recognize it. Is this just something I can't do? Background: I'm trying to include the full version of jQuery in DEBUG mode (for, well, debugging =) ), and the minified version for release. I tried this, but I'm not terribly familiar with the ASPX <% syntax...

Should I use #include in headers?

Is it necessary to #include some file, if inside a header (*.h), types defined in this file are used? For instance, if I use GLib and wish to use the gchar basic type in a structure defined in my header, is it necessary to do a #include <glib.h>, knowing that I already have it in my *.c file? If yes do I also have to put it between the...

Force Whitespace in C Macro?

I've got the following Macro to define a new function following a special naming scheme: #define CREATE_HOOK_STUB( func ) void ##func_STUB() { /* some code*/ } However, the preprocessor always concatenates void and ##func_STUB but I obviously want it to preserve the whitespace at that position. I know that I could just prepend some s...

C macro to transform a SVN revision to an integer

I am looking for a C/C++ macro that can transform a random SVN revision like "$Revision: 9 $" or "$Revision: 9999999 $" into an integer or a string. I know that simple functions exists to achieve this, but I want this to be made at compile time. My wish is to write things like:unsigned int rev = SVN_TO_INT("$Revision$"); ...