【C/C++】预定义宏

转载自:https://blog.csdn.net/weixin_43914889/article/details/105064843

C标准规定了一些预定义宏
在这里插入图片描述
C99 标准提供一个名为_ func 的预定义标识符,它展开为一个代表函数名的字符串(该函数包含该标识符)。那么, func 必须具有函数作用域,而从本质上看宏具有文件作用域。因此, func _是C语言的预定义标识符,而不是预定义宏。

注意,其中一些是C99 新增的,所以不支持C99的编译器可能无法识别它们。如果使用 GCC,必须设置-std=c99或-std=c11。

// predef.c -- 预定义宏和预定义标识符
#include <stdio.h>

void why_me();

int main()
{
	printf("The file is %s.\n", __FILE__);
	printf("The date is %s.\n", __DATE__);
	printf("The time is %s.\n", __TIME__);
	printf("The version is %ld.\n", __STDC_VERSION__);
	printf("This is line %d.\n", __LINE__);
	printf("This function is %s\n", __func__);
	why_me();
	return 0;
}

void why_me()
{
	printf("This function is %s\n", __func__);
	printf("This is line %d.\n", __LINE__);
}


//下面是该程序的输出:
The file is predef.c.
The date is Sep 23 2013.
The time is 22:01:09.
The version is 201112.
This is line 11.
This function is main
This function is why_me
This is line 21.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值