preprocessor

C++ Circularly declaring Preprocessor directives? Or defines before includes?

I'm a bit new to C++, so bear with me. I'm trying to figure out where exactly to place my #defines and #includes in my project. I have something like this: main.h #include "other.h" #define MAX_GROUPS 100 struct Cat { int something[MAX_GROUPS]; } In other.h I also need to use MAX_GROUPS, so do I also define MAX_GROUPS in other....

Weird C++ preprocessor problem

Hi, I've distilled my problem down to this code snippet - but it is a part of a larger program so I don't want a different way to do this - I need a way to make this work! When I generate a preprocessed file from this code: #define OUTER(a, b) \ a##b #define INNER(c, d) \ c##d enum foo { OUTER(INNER(x, y), z) }; // line 1...

Import Header-File depending on the target name in Xcode

I have a preprocessor constant called TARGET_NAME holding the current target name. I want to import a certain header file depending on the target name, e.g. include "App-Config.h" when TARGET_NAME is set to App-Config. How am I going to achieve this? ...

Can boolean operators be used with the preprocessor?

I wondering if it possible to have a preprocessor OR or AND statement? I have this code where I want to run under _DEBUG or _UNIT_TEST tags(?). What I want is something like the following: #if _DEBUG || _UNIT_TEST //Code here #endif If this is not possible, is there a workaround to achieve the same thing without having to duplicat...

Windows Mobile 6.5.3 preprocessor

Is there a preprocessor value I can use to detect when the program is being compiled for Windows Mobile 6.5.3? For example, I can use #if (_WIN32_WCE >= 0x501) to compile the code for Windows Mobile 5 and later, or #if _WIN32_WCE >= 0x502 to compile the code for Windows Mobile 6. There are some new API that exist in Windows Mobile 6.5....

C Preprocessor, Stringify the result of a macro

Hi, I want to stringify the result of a macro expansion. I've tried with the following: #define QUOTE(str) #str #define TEST thisisatest #define TESTE QUOTE(TEST) And TESTE gets expanded to: "TEST", while I'm trying to get "thisisatest". I know this is the correct behavior of the preprocessor but can anyone help me with a way to ac...

C Preprocessor, Macro "Overloading"

Hi, I'm trying to do some kind of Macro "Overloading", so that MACRO(something), gets expanded differently than MACRO(something, else). Using a snippet I got from here (I'm not sure if it's 100% portable) and some functions from the Boost PP Library, I was able to make it work :D //THESE TWO COUNT THE NUMBER OF ARGUMENTS #define VA_NA...

Which backend languages should my compiler target?

I've written a compiler for a general-purpose programming language that produces an optimised parse tree of its input. This intermediate format is then run through a preprocessor to translate it into a target language for subsequent compilation to a native executable. At present the only target language is C++, but I'd like to offer oth...

What does this line of C/C++ preprocessor mean?

This is Line 519 of WinNT.h (BUILD Version: 0091) #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name Why do we need a pointer to an struct with a single int member with a weird name called unused? And will we ever need to use a line of code like this one? HINSTANCE hInstance = new HINSTANCE__; ...

Concatenating qt-specific keyword and macro argument with a space in between

My problem is quite simple. I want the following macro #define PROXYPASS(name, param) \ void MyClass::sl_name(param _param) { \ emit name(_param); \ } to expand PROXYPASS(clientAdded, Client*) to: void MyClass::sl_clientAdded(Client* _param) { \ emit clientAdded(_param); \ } but since it ain't working i.e. it still shows ju...

Including header file defined by macro

I need to provide configuration file, which will describe which STL header files to include. I have found that usually it is done by defining a lot of HAVE_XXX_HEADER macros. I wonder if there's something wrong with explicitly providing header name in a macro. Then instead of testing each variant: #if defined(HAVE_TR1_UNORDERED_MAP_HEAD...

Preprocessor based exclusion of namespace qualified function calls.

I’m currently working on a reporting library as part of a large project. It contains a collection of logging and system message functions. I’m trying to utilize preprocessor macros to strip out a subset of the functions calls that are intended strictly for debugging, and the function definitions and implementations themselves, using cond...

How can you find whether an environment variable exists at compile time?

I don't particularly know if this is a good thing or not but I used to work somewhere where everyone had an environment variable like YOUR_NAME on their computer. Then if you had a bit of debug code that was only of interest to yourself you could wrap it in #if defined( YOUR_NAME ) and it wouldn't even be compiled for someone else unless...

Can I default a function argument to the value of __FILE__ at the caller?

In C++, can I have a defaulted argument to a function which defaults to __PRETTY_FUNCTION__, __FILE__, and __LINE__ as defined at the point of the caller and not the point the defaults are supplied in a header file without using macros? ...

Naming throw-away identifiers of global scope

Sometimes, when using macros to generate code, it is necessary to create identifiers that have global scope but which aren't really useful for anything outside the immediate context where they are created. For example, suppose it's necessary to compile-time-allocate an array or other indexed resource into chunks of various sizes. /* P...

Possible to abstract this logic with macro?

Hi all, I have thousands of function wrappers which inside actually perform a similar logic like: // a, b, ... are variable length parameters of different type void API_Wrapper(hHandle, a, b, ..) { if (hHandle) return remote_API(hHandle, a, b, ..); else return API(a, b, ..); } I wanna use a macro to reuse the if-else logic so ...

What is the reason for #pragma once inside header guards?

Just seen this inside <boost/asio.hpp> #ifndef BOOST_ASIO_HPP #define BOOST_ASIO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) /// .... #endif // BOOST_ASIO_HPP Disregarding the _MSC_VER preprocessor checks, what is the benefit of having the #pragma once in this case...

Can you please explain this piece of code?

#include <stdio.h> #include CONST15 #define CONST2 CONST2*CONST1 #define CONST3 CONST2+CONST2 int main(int argc,char**argv) { printf("%\n",CONST3); } ...

preprocessor directive

what exactly is a preprocessor directive .?? i do have an idea that #include is a preprocessor directive but what does it exactly do ..?? ...

Generic preprocessor: How to use for any kind of file?

Hi, I was wondering if someone uses a generic preprocessor for manipulating text files. The idea came up, as Java does not have a preprocessor, but I'd like to have conditional code compilation, etc. Now, taking that idea further, I might as well use a generic preprocessor for any kind of files that need frequent editing, but all edits...