Preprocessor Macros

Jan 28, 2011 at 5:17pm
Hi i wanted to write some advanced Preprocessor Macros. Therefor i tryed to
define a macro inside of an other macro
 
#define CREATE_FUNC(FUNCNAME) #define FUNCNAME(STRING) cout << STRING 

something like this.
But you cant use the preprocessor commands inside of a macro definition...or i dont know how.

is there an other way which works correctly

thx for any help!
Jan 28, 2011 at 5:25pm
The preprocessor is run only once so you cant nest definitions or have recursion.
Jan 28, 2011 at 5:26pm
May I ask you why exactly you are doing this? Doing these do not really make any sense at all, because in the first place, it doesn't even supply you with something regular defines can't handle.

EDIT:
Bazzy beat me to it, I was actually thinking that was the case too. But still the question remains, why do this? There might not be a point in doing it or there could be a reasonable way to do it instead.
Last edited on Jan 28, 2011 at 5:27pm
Jan 29, 2011 at 1:00pm
ofc there is a reason.
In the moment im creating real functions for logging with macros. this works fine and it saves a lot of time. my problem is that it would be nice to create this functions as macros. this is good cause of the performance. then you can disable the logging wihtout any functions calls and performance loose.
Jan 29, 2011 at 1:54pm
I tend to do the same with this:

1
2
3
#ifdef LOGGING
logFile << loggingData;
#endif 


If you want logging mode, you compile with the switch -DLOGGING (or similar if you're not compiling with gcc). No other changes.

Last edited on Jan 29, 2011 at 1:58pm
Jan 29, 2011 at 2:04pm
well my logging is a little bit difficulter. the application has about 20 different modules and every different modul should log into different files. then i use different log level definition for each modul and you should disable each of them seperatly. if you write this defines manually for all 20 modules you need to much time and hundreds of lines of code.
Thats why i create the logging functions with macros. but like i said this are real functions and not macros....
Jan 29, 2011 at 2:43pm
Have you looked into templates?
Jan 29, 2011 at 3:16pm
this could be a solution, but with a lot of work^^
Topic archived. No new replies allowed.