C 语言宏的用法

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);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值