我想了解我的编译器在C语言中的错误。未知类型名称错误与typedef结构和extern声明 - 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;
然后我宣布这个新的变量为extern在temperature.h中可以使用它在另一个文件中:
extern ButterwothSecondOrderFilterParameter_str TMP_TemperatureLowPassFilterParameter_STR;
对于* .c文件我只包含他的相关* .h文件,如果我需要另一个* .h文件的全局变量,我将它包含在* .h文件中
例如,temperature.c只包含temperature.h并且可以访问typedef application.h的结构我在temperature.h中包含application.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',并且文件应该被编译(这使得头文件是独立的)。目前,该文件不能编译;标题不是独立的。标题保护用于确保标题是幂等的;即使它们包含多次,其效果与包括它们一次相同。 –
而不是用单词解释,用代码解释:请提供[mcve]。目前还不清楚你的问题来自哪里。 – user694733