【发布时间】:2017-03-23 00:21:19
【问题描述】:
我想了解我的 C 语言编译器的错误。
在文件 application.h 中,我创建了一个 typedef 结构:
typedef struct
{
FLOAT64 CoefficientA1_F64;
FLOAT64 CoefficientA2_F64;
FLOAT64 CoefficientB0_F64;
FLOAT64 CoefficientB1_F64;
FLOAT64 CoefficientB2_F64;
FLOAT32 OldOldRawValue_F32;
FLOAT32 OldRawValue_F32;
FLOAT32 RawValue_F32;
FLOAT32 OldOldFilteredValue_F32;
FLOAT32 OldFilteredValue_F32;
FLOAT32 FilteredValue_F32;
}ButterwothSecondOrderFilterParameter_str;
然后我在另一个文件 temperature.c 中创建变量:
ButterwothSecondOrderFilterParameter_str TMP_TemperatureLowPassFilterParameter_STR;
然后我在 temperature.h 中将这个新变量声明为 extern,以便在另一个文件中使用它:
extern ButterwothSecondOrderFilterParameter_str TMP_TemperatureLowPassFilterParameter_STR;
对于 *.c 文件,我只包含他的相关 *.h 文件,如果我需要另一个 *.h 文件中的全局变量,我将其包含在 *.h 文件中
例如 temperature.c 仅包含 temperature.h 并且要访问 application.h 的 typedef 结构,我将 application.h 包含在 temperature.h 中。
对于我的 *.h 文件,我总是用 :
封装#ifndef xxxx
#define xxxx
#endif
这是最后一个产生错误的声明:
Description Resource Path Location Type
unknown type name 'ButterwothSecondOrderFilterParameter_str'
我不知道我的错误在哪里......?
【问题讨论】:
-
如果只包含
temperature.h头文件,而不包含application.h头文件,那么编译器如何知道ButterwothSecondOrderFilterParameter_str是什么符号? -
temperature.h必须包含application.h才能知道类型。您应该能够在temperature.c的顶部包含temperature.h(仅)并且文件应该编译(这使得标题自包含)。目前,该文件无法编译;标头不是独立的。标头保护用于确保标头是幂等的;即使多次包含,效果也与包含一次相同。 -
不要用文字解释,用代码解释:请提供minimal reproducible example。目前尚不清楚您的问题来自哪里。