【问题标题】:Function signatures in export file (*.h) using bool return type使用 bool 返回类型的导出文件 (*.h) 中的函数签名
【发布时间】:2014-08-07 23:22:54
【问题描述】:

我有一个文件:

// mylib.c
// -------

#include <stdbool.h>

bool is_zero(int n)
{
  return (n == 0);
}

还有一个文件详细说明要导出的功能:

// mylib.h
// -------

bool is_zero(int n);

当我编译时,我得到“mylib.o: error: unkown type name 'bool'”

我错过了什么吗?当我的导出函数的签名需要导出类型时,我是否需要做一些特别的事情?

【问题讨论】:

  • Erm ...删除mylib.h,如果你不#include它,那么它是没有意义的。它实际上被包含在 somewhere 是您要解决的真正问题。删除它会告诉你在哪里:) 将 stdbool.h 的#include 放在那个文件中,很容易。

标签: c gcc compiler-construction


【解决方案1】:

您还需要在mylib.h 中包含stdbool.h

bool 是一个扩展为_Bool 类型的宏,这个bool 宏在stdbool.h 中定义。

【讨论】:

    【解决方案2】:

    正确的做法是将#include &lt;stdbool.h&gt; 移动到mylib.h,然后将mylib.h 包含在mylib.c 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 2019-08-08
      • 2016-07-06
      • 1970-01-01
      • 2021-08-31
      相关资源
      最近更新 更多