您可以让 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;
^