__FUNCTION__、__FILE__等调试宏

C语言提供了很多宏,今天学习的过程中见到了__FUNCTION__这个宏,顺便百度了一下其它常见的宏,这些都是编译器内置的宏。下面找了几个简单的例子。

__FUNCTION__:当前函数的名称
__FILE__:当前文件的名称
__DATE__:代码运行时的日期
 __TIME__:代码运行时的时间
 __LINE__:所在行数

参考代码:

#include <stdio.h>

void test()
{
        printf("Another function is: %s\n", __FUNCTION__);
}

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 line is %d\n", __LINE__);
        printf("This function is %s\n", __FUNCTION__);

        test();
        return 0;
}

运行结果:

The file is macro.c
The date is Mar 29 2022
The time is 17:15:26
This line is 13
This function is main
Another function is: test
posted @ 2022-03-31 15:54  些许潦草  阅读(337)  评论(0)    收藏  举报