__FILE__ __FUNCTION__ __LINE__的使用

#include <stdio.h>
#include <stdlib.h>

int main()
{
    
    
    printf("%s\n", __FILE__);

    printf("%s\n", __FUNCTION__);
    printf("%s\n", __func__);

    printf("%d\n", __LINE__);
    printf("%d\n", __LINE__);

    printf("%s\n", __DATE__);
    printf("%s\n", __TIME__);

    char buf[100];
    sprintf(buf, "%s : %s() : %d", __FILE__, __FUNCTION__, __LINE__);
    puts(buf);

    return 0;
}
[root@lwh TheSwordRefersToOffer]# gcc test.c 
[root@lwh TheSwordRefersToOffer]# ./a.out 
test.c
main
main
11
12
Oct  9 2020
22:06:57
test.c : main() : 18
[root@lwh TheSwordRefersToOffer]# 

猜你喜欢

转载自blog.csdn.net/liangwenhao1108/article/details/108987374