1.常用的宏定义
ANSI c语言标准宏
_LINE_ //在原代码中显示当前行号
_FILE_ //在源代码中超入当前源文件名
_DATE_ //显示当前日期
_TIME_ //显示当前时间
_VA_ARGS_ //一个可变参数的宏
_func_ //打印出当前函数
#include <iostream>
#include <string>
#include <utility>
using namespace std;
// ANSI c语言标准宏
//_LINE_ //在原代码中显示当前行号
//_FILE_ //在源代码中超入当前源文件名
//_DATE_ //
//_TIME_ //在源代码中插入当前的编译时间
//_VA_ARGS_ //一个可变参数的宏
//_func_ //打印出当前函数
//#用于将参数转化成字符串
//## 用于拼接字符串
#define log() printf("line:%d,tine:%d,func:%s\n", __LINE__,__TIME__,__func__)
int main()
{
printf("line:%d\n", __LINE__);
printf("TIME:%d\n", __TIME__);
printf("func:%s\n", __func__);
log();
}
运行结果
2. # 和##
# 将当前变量字符话
## 是将字符串进行拼接
3.如何判断一个指针是否为null
#include <iostream>
#include <string>
#include <utility>
using namespace std;
#define SUM_NUMBER 100
#define MAX(X,Y) X*Y
#define LOG(x) do { printf("%s=%d\n",#x,x); }while(0)
#define LOG1(_Z_) _Z_==nullptr? printf("%s is nulll\n",#_Z_):printf("get %s sucess\n",#_Z_);
int main()
{
int ptr1 =1;
int* ptr2 = nullptr;
LOG1(&ptr1);
LOG1(ptr2);
}