Siemel said:
Thanks. This works, in addition to the suggestion Pete gave. Out of
curiosity, if have a macro
#define SOME_MACRO myfunction(__LINE__)
and we rewrite it as
#define SOME_MACRO myfunction( \
__LINE__)
will the line number passed to myfunction be the same in the following
program:
int main() { // line 10
SOME_MACRO; // will this call myfunction(10) or myfunction(11)?
}
Why don't you just try it?
Well, concatenation of lines with the \ between them happens _before_ any
macro substitution. Since __LINE__ is a macro, the substitution has to
happen _after_ the concatenation, so the 'SOME_MACRO' example you gave
should be considered as a single line. That's basically how you can make
your macro register where it was placed in the code. Of course it does
*not* prevent you from doing
SOME_MACRO; SOME_MACRO;
and have two calls with the same value at run time, since both macros get
the same __LINE__ substitution.
V