gpt4 book ai didi

c - Typedef 在 header 中无效

转载 作者:太空宇宙 更新时间:2023-11-04 06:02:20 24 4
gpt4 key购买 nike

我有一个结构如下的 C 项目:

Project
- fileA.h
- fileA.c
+ subdirB
- fileD.h

fileD.h中有一个bool的typedef枚举:

typedef enum bool {
false = 0, /**< false (0) */
true /**< true (1) */
} bool;

在 fileA.c 中有几个使用 bool 作为参数的函数,因此包含了 fileD.h:

#include "subdirB/fileD.h" // header with bool typedef
#include "fileA.h" // own header with foo declaration
...
int foo (bool bar) {
...
return 0;
}
...

这些函数将成为全局函数,因此它们的声明被添加到头文件 A.h 中:

int foo (bool bar);

然而,这最后一点给了我一个错误,“标识符 bool 未定义”……我不明白为什么会这样??

最佳答案

您是否将 fileD.h 包含在 fileA.h 中?为了声明一个接受 bool 值的函数,编译器需要知道什么是 bool 值。

关于c - Typedef 在 header 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17049942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com