tags:

views:

28

answers:

1

Hello all,

I have a macro that I use to `goto', I want to let the macro know about the label.

Example:

#define MYMACRO((a),(b)) printf("I have arg: %s, %s with Label: %s at line %d", (a), (b), _GETLABEL_, __line__)    
mylabel: MYMACRO("a1","a2")

This should print: I have arg: a1, a2 with Label: mylabel at line 4

Is it possible to implement GETLABEL? Will it be portable?

Thanks in advace, Tarek

+2  A: 

Let the macro create the label:

#define MYMACRO(label, a, b) \
    label : printf("I have arg: %s, %s with Label: %s at line %d", \
    (a), (b), #label, __LINE__)    

Then

MYMACRO(mylabel, "a1", "a2");

will evaluate to

mylabel : printf("I have arg: %s, %s with Label: %s at line %d", ("a1"), ("a2"), "mylabel", 42);
Christoph