警告:ISO C禁止空翻译单元
在一个头文件中,我有下面的代码,它在尝试链接时给出了标题中的错误警告:ISO C禁止空翻译单元,c,macros,C,Macros,在一个头文件中,我有下面的代码,它在尝试链接时给出了标题中的错误 #ifndef BOOLEAN_H #define BOOLEAN_H #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE !FALSE #endif #endif indicating the error occurs in the line of the last #endif 当使用-pedantic编译时,gcc会根据C标准的要求报告翻译
#ifndef BOOLEAN_H
#define BOOLEAN_H
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE !FALSE
#endif
#endif
indicating the error occurs in the line of the last #endif
当使用
-pedantic
编译时,gcc
会根据C标准的要求报告翻译单元为空时的诊断。要使gcc
满意,可以在空的.c
文件中添加一个伪typedef
:
typedef int make_iso_compilers_happy;
或
为什么要编译头文件?@mafso:compiler会检查很多东西,而不仅仅是生成机器代码。这有助于检测打字错误、遗漏等。我想知道为什么ISO C禁止空翻译单元
extern int make_iso_compilers_happy;