preprocessor

C Macros to create strings

I would like to use C #define to build literal strings at compile time. The string are domains that change for debug, release etc. I would like to some some thing like this: #ifdef __TESTING #define IV_DOMAIN domain.org //in house testing #elif __LIVE_TESTING #define IV_DOMAIN test.domain.com //live testing servers #else ...

C preprocessor on Mac OSX/iPhone, usage of the '#' key?

I'm looking at some open source projects and I'm seeing the following: NSLog(@"%s w=%f, h=%f", #size, size.width, size.height) What exactly is the meaning of '#' right before the size symbol? Is that some kind of prefix for C strings? ...

C++ Macros: manipulating a parameter (specific example)

I need to replace GET("any_name") with String str_any_name = getFunction("any_name"); The hard part is how to trim off the quote marks. Possible? Any ideas? ...

Is there a way to assign conditional methods or add preprosessor directives at run-time in C# ?

The aim is to be able to switch debugging calls on at run-time from database on a production build ... ...

Variadic recursive preprocessor macros - is it possible?

I've run into a little theoretical problem. In a piece of code I'm maintaining there's a set of macros like #define MAX_OF_2(a, b) (a) > (b) ? (a) : (b) #define MAX_OF_3(a, b, c) MAX_OF_2(MAX_OF_2(a, b), c) #define MAX_OF_4(a, b, c, d) MAX_OF_2(MAX_OF_3(a, b, c), d) ...etc up to MAX_OF_8 What I'd like to do is replace them wi...

How much one can do with (higher order) macros?

Is it "safe" to give macros names as arguments to other macros to simulate higher order functions? I.e. where should I look to not shoot myself in the foot? Here are some snippets: #define foreach_even(ii, instr) for(int ii = 0; ii < 100; ii += 2) { instr; } #define foreach_odd(ii, instr) for(int ii = 1; ii < 100; ii += 2) { instr; }...

Is #define supposed to add spaces around macros?

I was looking at the program at http://www0.us.ioccc.org/1988/westley.c, mentioned in another SO answer - it's supposed to print the value of pi, about 3.142, but when I compile it and run it I get 0.250. It looks like when the GCC preprocessor (both 4.1.2 and 3.4.6 tested) runs on the code, it converts #define _ -F<00||--F-OO--; _-_-_...

Is there a convenient function in objective-c / coca-touch to find a lowest number?

I have two numbers, and need to get returned the lower one. Is there any function I could use? Sure it's a easy task, I could do an if-statement. I just want to know. ...

Is there a simple preprocessor/code-generator like GNU M4 that can be called from Ant?

I need to maintain some old XSL code and I've discovered that there's a lot of duplication in the XSL files. It looks like there isn't an easy include/import function for XSL which would allow me to move the code to a different file and just include it when needed. This sounds like it could be done with Model Driven Development tools b...

Alternatives to preprocessor directives

Hi, I am engaged in developing a C++ mobile phone application on the Symbian platforms. One of the requirement is it has to work on all the Symbian phones right from 2nd edition phones to 5th edition phones. Now across editions there are differences in the Symbian SDKs. I have to use preprocessor directives to conditionally compile code...

Macro-producing macros in C?

I'd like to get the C preprocessor to generate macros for me (i.e., I'm using C99 only). I'd write a macro #define make_macro(in) <...magic here...> and when I put make_macro(name1) make_macro(name2) later in the code, it would expand to #define name1(...) name1_fn(name1_info, __VA_ARGS__) #define name2(...) name2_fn(name2_info, _...

What preprocessor directive or other method should I use to discern 32- vs 64-bit environment?

I would like to compile the following C program for 32- and 64-bit systems. #include <stdio.h> #include <stdlib.h> ...

How can I remove the duplication between these C macros?

I have the following couple of C pre-processor macros for creating test functions: // Defines a test function in the active suite #define test(name)\ void test_##name();\ SuiteAppender test_##name##_appender(TestSuite::active(), test_##name);\ void test_##name() which is used like this: test(TestName) { // Test code h...

Java - keeping multi-version application from splitting codebase

I am writing an application that will ship in several different versions (initially around 10 variations of the code base will exist, and will need to be maintained). Of course, 98% or so of the code will be the same amongst the different systems, and it makes sense to keep the code base intact. My question is - what would be the prefer...

Preproccessor ignore

I am migrating from Visual Studio 6 to Visual Studio 2008 and I have a function of a component I am using named SetDefaultPrinter. Unfortunately there is a windows library function now, SetDefaultPrinter, with the same name. And the macro associated with it is getting in the way of me using my function. This is my workaround I have to ...

How to use preprocessor to compute and store hashes at compile time?

I have a native C++ program that uses "event queues" to execute functions on different threads. I allocate an "event" class on the heap, and put it on one of my threads' queues for execution. It all works great, but it's very difficult to trace back the origin of these "events". I would like each "event" to store some information pertai...

How to tell the preprocessor to search for a particular folder for header files, when I say #include <xyz.h>

I have around 120 header files(.h files) , and in all of them each one includes many other header files using #include , but as I kept .h files in a specific folder, preprocessor is generating filenotfound error. I moved all the .h files to the single .C file that is calling the first headerfile. One way to do is make #include as #inc...

Visually marking conditional compilation

We have a large amount of C/C++ code that's compiled for multiple targets, separated by #ifdefs. One of the targets is very different from the others and it's often important to know if the code you're editing is compiled for that target. Unfortunately the #ifdefs can be very spread out, so it's not always obvious which code is compile...

list of #pragma warning disable codes and what they mean

The syntax for disabling warnings is as follows: #pragma warning disable 414, 3021 Or, expressed more generally: #pragma warning disable [CSV list of numeric codes] Is there a list of these numeric codes and the description of the warning that they're suppressing? Much to my chagrin, I can't seem to locate it via Google. ...

Confused about C macro expansion and integer arithmetic

I have a couple of questions regarding the following snippet: #include<stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]); return 0; } Here the output of the code does not print the array eleme...