#define RUN_SOME_STUFF(...) { \ int x = 0; \ printf("[INFO] Do some stuff here ... %d\n", ++x); \ {__VA_ARGS__} \ printf("[INFO] end some stuff here\n"); \ }
How do I use it:
... RUN_SOME_STUFF( { // middle: int y; y = 100; printf("Middle\n"); }); ...
Now I know that this is seen as a (very) ugly macro, but this is the main reason I seek help.
The first problem with this: if any type of error appears, the compiler will show the last line of the macro as an invalid line. Printouts are just examples to simplify the problem (in both code snippets), so there can be 20 lines of complex, embedded code, in which case it is very annoying.
The second is that __LINE__ is resolved in the same wrong way
& I'm sure there are many more ...
1. Is there a way to fix the above problems so that the strings are resolved correctly? (maybe some kind of compiler option?) I am using VS2008 / 2010)
2. If there is no way to do this using the macro in a โcuteโ way, do I have any other options for this? I just want to run the code around (before and after) some other code.
Edit: I would often use this macro, always with a different โaverageโ content, so I cannot write an inline function every time.
source share