• customized print macro/##__VAR_ARGS__


    customized print macro

    #define DEBUG_INFO(fmt, ...)  printf(fmt, __VA_ARGS__)

    then you can use DEBUG_INFO() macro to print debug info like printf.

    example:

    DEBUG_INFO("name: %s, age: %d ", "hello world!", 26);

    notice:

    a. __VA_ARGS__ is pre-defined macro in C.

    b. DEBUG_INFO(fmt, ...), the ... in this macro definition represents(can only represent) the last argument of this macro.

    the below form is wrong:

    #define DEBUG_INFO(fmt, ..., A)

    c. the below form is also correct:

    #define DEBUG_INFO(fmt, var_args...)  printf(fmt, ##var_args)

    2. ##__VAR_ARGS__

    #define CUSTOM_PRINT(fmt, ...)  printf(fmt, ##__VAR_ARGS__)

    a. the ## before __VAR_ARGS__ is used to tell compiler to remove the comma before ##__VAR_ARGS__ under the variable argument list is null to avoid complile error(unnecessary comma before __VAR_ARGS__) under this case.

  • 相关阅读:
    JDBC连接MySQL并且查询操作。
    struts
    KMP 剪花布条hdoj2087
    线段树---敌兵布阵hdoj 1166
    设计模式----观察者模式
    线段树--hdoj1754
    ZOJ 2283 Challenge of Wisdom
    SGU 134 Centroid
    UVA 1637 Double Patience
    HDU 4389 X mod f(x)
  • 原文地址:https://www.cnblogs.com/aspirs/p/7111566.html
Copyright © 2020-2023  润新知