开发者

Get the label beside my Macro inf a C-code

开发者 https://www.devze.com 2023-01-22 00:40 出处:网络
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_, _

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开发者_Go百科 GETLABEL? Will it be portable?

Thanks in advace, Tarek


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消