preprocessor

g++ __FUNCTION__ replace time

Hi, can anyone tell when g++ replaces the __FUNCTION__ 'macro' with the string containing the function name? It seems it can replace it not until it has check the syntactical correctness of the source code, i.e. the following will not work #include <whatsneeded> #define DBG_WHEREAMI __FUNCTION__ __FILE__ __LINE__ int main(int argc, ch...

why # is required before #include<stdio.h>?

what is the function of #? ...

Why other languages don't support something similar to preprocessor directives like C and its descendant?

Hi,I wonder why other languages do not support this feature. What I can understand that C / C++ code is platform dependent so to make it work (compile and execute) across various platform, is achieved by using preprocessor directives. And there are many other uses of this apart from this. Like you can put all your debug printf's inside #...

How can I guarantee full macro expansion of a parameter before paste?

I have a general macro: #define mSwitch( Root, Case ) Root##_Case_##Case #define mSpecialDisplay( what, Val ) mSwitch(mSpecialDisplay,what)(Val) #define mSpecialDisplay_Case_Int(Val) ...do stuff #define mSpecialDisplay_Case_Float(Val) ...do stuff ...more special cases how do I guarantee that the variable Case is fully expanded ...

Purging Preprocessing Macros

Hi! This is an odd problem, so I have to provide a bit of background. I have a C++ project that I'm working on that I want to clean up a bit. The main issue that I'm dealing with that makes me want to barf is the massive abuse of preprocessor macros that are used in a core component of the project. There's a file with a bunch of #define...

Struct initialisation through macro overuse

Hi, I've got some structs to initialise, which would be tedious to do manually. I'd like to create a macro that will help me with it... but I'm not sure C preprocessor is good enough for this. I've got structs which represent menus. They consist of function pointers only: typedef uint8_t (*button_handler) (uint8_t); typedef void (*peda...

Accessing the value of a Preprocessor Macro definition

If I add a macro "FOO=bar" under GCC_PREPROCESSOR_DEFINITIONS (or Preprocessor Macros if you use XCode"), what would be the best way to access the value of "FOO"? Currently, I use the clumsy: #define MACRO_NAME(f) #f #define MACRO_VALUE(f) MACRO_NAME(f) #ifdef FOO NSLog(@"%s", MACRO_VALUE(FOO)); #else ...

trying to understand the c preprocessor

why do these blocks of code yield different results? some common code: #define PART1PART2 works #define STRINGAFY0(s) #s #define STRINGAFY1(s) STRINGAFY0(s) case 1: #define GLUE(a,b,c) a##b##c STRINGAFY1(GLUE(PART1,PART2,*)) //yields "PART1PART2*" case 2: #define GLUE(a,b) a##b##* STRINGAFY1(GLUE(PART1,PART2)) //yields "works*"...

Rounding in C Preprocessor

Hi, I am defining some values in the preprocessor. e.g. #define a 1000 #define b 0.5*a when I try to use b in a place where integer is needed I get an error. I don't want to cast b always in my code and do it once in the #define line, is that possible? ...

variable "undeclared" in "#pragma" command?

I'm compiling a branch of the Blender 3D modeling program from source (using SCONS), on a Fedora 8 box, and am running into an error that I didn't encounter compiling the same source on a CentOS 5 box, and I'm thinking it has to do with the variable definition. The error is: source/blender/blenkernel/intern/implicit.c: In function ‘mul_...

Looking for a preprocessor to fill in static files

What I'm looking for would allow me to take something like this: index.html.template: <html> <body> <# include ("body.html.template") #> </body> </html> body.html.template: Hello World! <# include("text.txt") #> text.txt: 4 And turn it into this: <html> <body> Hello World! 4 </body> </html> While the example is HTML, I would...

Is there a way to do a #define inside of another #define?

I know that I am trying to shoot myself in the leg ;) However, it will allow me to make the rest (big amount) of code smaller and more readable. Is there any tricky way to create preprocessor macro inside of another preprocessor macro? Here is the example, what I am looking for. My real scenario is more complex // That's what I want ...

Can I force the C pre processor to generate a new line ?

Possible Duplicate: How can I make the preprocessor insert linebreaks into the macro expansion result? #define IDENTIFIER { /*new line here*/\ my_multiline(); /*new line here*/\ macro(); /*new line here*/\ } /*new line here*/ Can I force the C pre processor to generate a new line in it's expan...

C/C++ need a clever way to track function calls

I am looking for a clever way to track function calls and returns. I know I can use the debugger, but I would like a way to just have it print something out to the terminal when calling a function vs having to step through code. I am thinking that I might be able to use the preprocessor, but I am not sure what would be the best way to go...

#pragma pack effect

I was wondering if someone could explain to me what the #pragma pack preprocessor statement does and more importantly why one would want to use it. I checked out the msdn on this http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx, which offered some insight, but I was hoping to hear more from people with experience. I've seen i...

Argument Preceded by a # Token in a Macro

#define LINK_ENTITY_TO_CLASS(mapClassName,DLLClassName) \ static CEntityFactory<DLLClassName> mapClassName( #mapClassName ); This is a macro from the Alien Swarm mod for Half-Life 2, meant to be compiled with MSVC. I've never seen an argument preceeded by a # in a macro before, and I'm not sure if this is a MSVC specific thing or ...

Inno Setup: How do i see the output (translation) of the Inno Setup Preprocessor?

I have an Inno Setup script with preprocessor directives (#defines, #ifs, etc.) I want to run the Inno Setup preprocess on my script and see the preprocessor's output (translation in Inno-Setup-speak). That is, I want to look at the result of the preprocessor which it normally feeds into the Inno Setup Compiler, where all the references...

[javascript] EXTENDS challenge: preprocessor function macros and class-like oop

Background I've been using the C preprocessor to manage and "compile" semi-large javascript projects with multiple files and build targets. This gives full access to C preprocessor directives like #include, #define, #ifdef, etc. from within javascript. Here's a sample build script so you can test the example code: #!/bin/bash export OP...

#pragma inside #define

I'm working in a micro controller using C language. In this specific micro, the interrupts have to be defined using #pragma in following way: static void func(); #pragma INTERRUPT func <interrupt_address> <interrupt_category> static void func() { /* function body */ } The <interrupt_address> is address of the interrupt in vector table...

How to detect XCode vs Makefile build

I'ld like to automatically detect (using #ifdef) whether I'm building using XCode or using make under Darwin. Is there a specific define to XCode or make set automatically by either tool? I'ld like to avoid setting a define in the XCode project or Makefile manually. ...