您可以让gcc通过重新定义标志来确定标志在哪里定义以用于测试目的。
#include <limits.h>
#define INT_MAX 42
int f(void)
{
return INT_MAX;
}
将使GCC抱怨
main.c:4:0: warning: "INT_MAX" redefined [enabled by default]
#define INT_MAX 42
^
In file included from main.c:2:0:
/usr/lib/gcc/x86_64-redhat-linux/4.8.1/include/limits.h:120:0: note: this is the location of the previous definition
#define INT_MAX __INT_MAX__
^
同样的策略也很适合的情况下,寻找结构定义(非常有用的,你有几个建筑师特定的头文件,你不知道哪一个实际上是使用!)。
#include <stdio.h>
typedef void FILE;
void f(void)
{
}
给
main.c:3:14: error: conflicting types for ‘FILE’
typedef void FILE;
^
In file included from main.c:1:0:
/usr/include/stdio.h:48:25: note: previous declaration of ‘FILE’ was here
typedef struct _IO_FILE FILE;
^
难道真的THE_FLAG,还是你只是把它作为一个例子吗?如果这个名称足够独特,那么我只需要在系统上grep所有头文件。 – Chris
只是示例:) –