c标准中的预定义宏

ANSI C标准中有几个标准预定义宏:
__LINE__:在源代码中插入当前源代码行号;
__FILE__:在源文件中插入当前源文件名;
__DATE__:在源文件中插入当前的编译日期
__TIME__:在源文件中插入当前编译时间;
__func__: 当前所在函数名,在编译器的较高版本中支持
__FUNCTION__: 当前所在函数名

使用实例

#include <stdio.h>
#include <stdlib.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( "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( "The file is %s.\n", __FILE__ );
    printf( "This is line %d.\n", __LINE__ );
}
运行结果

The file is debug.c.
The date is Jun  6 2012.
The time is 09:36:28.
This is line 11.
This function is main.
This function is why_me
The file is debug.c.
This is line 22.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值