开发者

Get the label beside my Macro inf a C-code

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜