preprocessor

how to figure out what value MSVC is using for a preprocessor macro

I'm attempting to use a /D compiler option on MSVC6 to define a string, but there's something weird about using double quotes around it. To debug this problem, it would be extremely helpful for me to be able to see what value the preprocessor is actually substituting into my code where the macro is expanded. Is there any way I can do t...

Java Preprocessor

If I have a boolean field like: private static final boolean DEBUG = false; and within my code I have statements like: if(DEBUG) System.err.println("err1"); does the Java preprocessor just get rid of the if statement and the unreachable code? ...

Detect usage of macro? (errno)

This is very specific, and a bit difficult to explain, and quite likely impossible, but here goes. Perhaps some C cracks out there have an idea... I want to implement <errno.h>. (My hobby project is implementing a Standard C library.) The naive way to go about it is: // in <errno.h> extern int errno; // in some .c file int errno = 0;...

Is there a way to apply an action to N C++ class members in a loop over member names (probably via pre-processor)?

The problem: I have a C++ class with gajillion (>100) members that behave nearly identically: same type in a function, each member has the same exact code done to it as other members, e.g. assignment from a map in a constructor where map key is same as member key This identicality of behavior is repeated across many-many functions (>2...

Is it possible to generate a global list of marked strings at compile time/runtime?

So, I'm working on translating my C++ app into multiple languages. What I'm currently using is something like: #define TR(x) (lookupTranslatedString( currentLocale(), x )) wcout << TR(L"This phrase is in English") << endl; The translations are from a CSV file which maps the english string to the translated string. "This phrase is in...

Specifying implementation of interface

Hi In my implementation I have a preprocessor definition that specifies the operating system the application is running on, e.g. OS_WIN or OS_LINUX. In a header file, I have defined the interface, that is the same for each operating system. //interface.h: void functionA(); void functionB(); I also have the implementations for the i...

offsetof at compile time

Is there a way of finding the offset of a member of a structure at compile-time? I wish to create a constant containing the offset of a structure member. In the following code the offsetof() macro works in the first printf statement. However, the use in line 10 to declare 'ofs' generates the error "Cannot resolve '->' operator as a const...

Is the C preprocessor able to process strings char by char?

I'd like to obscure strings at compile time. I know it can be done in other preprocessors but I haven't found a way to do this with the C preprocessor. ...

Using preprocessor directives in BlackBerry JDE plugin for eclipse?

How to use preprocessor directives in BlackBerry JDE plugin for eclipse? ...

C++: Force Preprocessor to use a previous definition in a redefinition

Update 3: Never mind. I kinda got what I was looking for. The following gives unique identifiers inside a class. static const int _counter_start = __COUNTER__; static const int val1 = __COUNTER__ - _counter_start; static const int val2 = __COUNTER__ - _counter_start; Update 2: Boost Preprocessor I will be implementing something ak...

Add Preprocessor to HTML (Probably in Apache)

I would like to add a preprocessor to HTML pages. Basically, I have a program that takes the name of an HTML file containing preprocessor instructions and outputs the contents of the file after preprocessing to stdout. This mechanism could change if it makes things easier. All I want to do is hook this into Apache so that all the file...

How to print a pound / hash via C preprocessor?

Hi, I need help doing the following: a preprocessor macro label(x) shall output "#x", e.g., #define label(x) ... if I call label(aname), the output shall be "#aname" I know, that the following tries were errors. #define label(x) #x // leads to "x" #define label(x) \#x // is \"x" #define label(x) "#x" // is "#x" (but not the cont...

cancelling std::cout code lines using preprocessor

One can remove all calls to printf() using #define printf. What if I have a lot of debug prints like std::cout << x << endl; ? How can I quickly switch off cout << statements in a single file using preprocessor? ...

C++ #define preprocessor

I need to know that does the #define directive in C++ declares global label? By global I mean visible in every file? I'm using Visual Studio 2008, (guess if that matters) ...

using #include to load opencl code

i've seen this done long ago with hlsl/glsl shader code. using a #include on the source code file that pastes the code into a char* so that no file io happens at runtime. if i were to represent it as pseudo-code it would look a little like this: #define CLSourceToString(filename) " #include "filename" " const char* kernel = CLSourceToS...

Printing the contents of a file using the #include directive (preprocessor)

Hi, Say i have a file, t.txt, that contains the following two lines: one two Now, I would like to write a program which will #include that file somehow and print its contents, nothing more. That is, i want the contents of that file to appear in my code as a static text, at compile time. Any ideas? The reason im asking is this: I ...

Pre-preprocessor

Hi, I want to have a C pre-preprocessor which is filtering some #define statements from the sourcecode without changing anything else. Why? This should be used to remove some client specific code from the sources if the source is handed out to another client. Does anyone know of an existing solution? Thanks! Simon ...

A C preprocessor macro to pack bitfields into a byte?

I'm getting into microcontroller hacking and while I'm very comfortable with bitwise operators and talking right to the hardware, I'm finding the resulting code very verbose and boilerplate. The higher level programmer in me wants to find an effective but efficient way to clean it up. For instance, there's a lot of setting flags in reg...

Xcode/GCC predefined macro for target name?

I was wondering if there is an Xcode or GCC preprocessor symbol for the target name of the application. For example if I'm building an application called "MonkeyChicken", is there a preprocessor symbol such that printf( __TARGET_NAME__ ) outputs: MonkeyChicken ...

Django custom context processor being called twice per request

I created a simple custom context processor that needs to only be run once per request. After putting in some logging hooks I found that it is being called twice per request. Is this a known "feature" that a missed in the docs? Is it related to the number of templates in the inheritance tree? Is it a bug in 1.03? Thanks. ...