【问题标题】:Warning: ISO C forbids an empty translation unit警告:ISO C 禁止空的翻译单元
【发布时间】:2014-10-24 03:44:46
【问题描述】:

在头文件中,我有以下代码,在尝试链接时,标题中出现错误。

#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 

【问题讨论】:

  • 为什么要编译一个头文件?
  • @mafso:编译器会检查很多东西,而不仅仅是生成机器码。这有助于检测错别字、遗漏等。

标签: c macros


【解决方案1】:

gcc 使用 -pedantic 编译时,当 C 标准要求翻译单元为空时报告诊断。为了让gcc 开心,您可以在空的.c 文件中添加一个虚拟typedef

typedef int make_iso_compilers_happy;

extern int make_iso_compilers_happy;

【讨论】:

  • 我很想知道为什么 ISO C 禁止空翻译单元
猜你喜欢
  • 2018-11-16
  • 1970-01-01
  • 2010-10-06
  • 1970-01-01
  • 2010-11-01
  • 1970-01-01
  • 2010-11-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多