zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    HTTP协议简介
    HTTP缓存带来的“bug”--HTTP 协议 Cache-Control
    PHP7变量的内部实现(一)
    PHP 简单的加密解密方法
    php 制作圆形图片
    python解决图的最短路径问题
    PHP中文关键词匹配
    D25
    D24
    D23
  • 原文地址:https://www.cnblogs.com/aspirs/p/7111566.html
Copyright © 2011-2022 走看看