代码之家  ›  专栏  ›  技术社区  ›  An̲̳̳drew Chad Okere

奇怪的C宏语法(#var)

  •  3
  • An̲̳̳drew Chad Okere  · 技术社区  · 17 年前

    例如

    #define my_setopt(x,y,z) _my_setopt(x, 0, config, #y, y, z)
    
    2 回复  |  直到 17 年前
        1
  •  7
  •   RichieHindle    17 年前

    这是最重要的 Stringizing Operator ,它将宏参数转换为字符串文字。

    在你的例子中:

    my_setopt(1, 2, 3)
    

    将扩大到:

    _my_setopt(1, 0, config, "2", 2, 3)
    
        2
  •  2
  •   sepp2k    17 年前

    # 引用表达式。例如:

    #define SHOW(BAR) printf("%s is %d\n", #BAR , BAR)
    SHOW(3+5);  // prints: 3+5 is 8