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\n", "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.

 

posted @   aspirs  阅读(347)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
点击右上角即可分享
微信分享提示