- 获取文件名、行号、函数名、时间、日期等
- 获取环境变量
输出示例:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
extern char **environ; //定义环境变量extern
// this file is test.c
// this line is 10
// this func is test
// the date is Jan 14 2022
// the time is 08:44:20
// if ansic 1
int test()
{
printf("this file is %s\n",__FILE__); //文件名
printf("this line is %d\n",__LINE__);//当前行数
printf("this func is %s\n",__FUNCTION__);//函数名称
printf("the date is %s\n",__DATE__);//date
printf("the time is %s\n",__TIME__);//time
printf("if ansic %d\n",__STDC__);//是否ansic标准
}
int main()
{
int i = 0;
test();
printf("hello\n");
for( i = 0;environ[i]!= NULL;i++)
{
printf("%d = %s\n",i ,environ[i]);//输出所有环境变量
}
}