Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
Last active September 6, 2021 03:11
Show Gist options
  • Save insaneyilin/86e5fb8744091d362b3df2a898322dfc to your computer and use it in GitHub Desktop.
Save insaneyilin/86e5fb8744091d362b3df2a898322dfc to your computer and use it in GitHub Desktop.
__VA_ARGS__ usage
#define MODULE_NAME "MY_LIB"
// __VA_ARGS__ 对应宏定义中参数列表的最后一个参数为省略号(也就是三个点)
// 加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错
#define error_print(fmt, ...) printf("[ERROR]["MODULE_NAME"](%s|%d)" fmt, __func__, __LINE__, ##__VA_ARGS__)
// 单个 # 用来把参数转换成字符串
// ## 是个粘合剂,将前后两部分粘合起来,也就是有“字符化”的意思。但是“##”不能随意粘合任意字符,必须是合法的C语言标示符。在单一的宏定义中,最多可以出现一次“#”或“##”预处理操作符。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment