打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux C 中连接操作符##
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#define test(x) test ## x
#define DPRINT( fmt, args...) \
{   \
    printf('File : %s Funtion : %s Line : %d  \t', __FILE__, __FUNCTION__, __LINE__ );\
    printf( fmt, ##args );\
}
voidtest1(inta)
{
    DPRINT('Integer : %d \n', a);
}
voidtest2(char*s)
{
    DPRINT('String : %s \n', s);
}
intmain(void)
{
    test(1)(100);
    test(2)('hello');
    return0;
}

打印信息:

***************************************************

 File : test.c Funtion : test1 Line : 11         Integer : 100
 File : test.c Funtion : test2 Line : 16         String : hello

***************************************************

 

#define DPRINT( fmt, args...) \
{ \
printf('File : %s Funtion : %s Line : %d  \t', __FILE__, __FUNCTION__, __LINE__ );\
printf( fmt, ##args );\
}

这样定义宏有个问题, 标准printf()函数有返回值, 只是我们很少用

另外一种定义:

#define DPRINT( fmt, args...)     \
  printf('File : %s Funtion : %s Line : %d  \t'fmt, __FILE__, __FUNCTION__, __LINE__ ,##args )

fmt不能为指针

*****************************************

const  char *s= 'string';

printf(s);

*****************************************

是合法的,可以打印出string

但DPRINT(s)就不合法

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C/C++中#,##,\,
bug解决不了?使用日志法
命令行参数,命令行标志,环境变量
Simple way to copy a file in golang
JNI相关类型转换
Java|print、println与printf的区别
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服