好的,我看到这是一个相当普遍的问题,但我找不到与我的问题类似的问题。
我不断遇到问题
identifier "Baserate" is undefined
Run Code Online (Sandbox Code Playgroud)
我将其定义为
时间
#include "tim_api.h"
enum Baserate {
Rate_62_5ns = 0x0,
Rate_125ns = 0x1,
Rate_250ns = 0x2,
Rate_500ns = 0x3,
Rate_1us = 0x4,
Rate_2us = 0x5,
Rate_4us = 0x6,
Rate_8us = 0x7,
Rate_16us = 0x8
};
Run Code Online (Sandbox Code Playgroud)
问题是当我定义它使用的函数时
tim_api.h
extern void TIM_Set_Period_ns(int Timer_Select, Baserate Set_Baserate, int Period);
Run Code Online (Sandbox Code Playgroud)
这是我在构建嵌入式 c 程序时,但是当我在 ac consol 应用程序中运行它时,它可以工作
void TIM_Enable(Baserate my_baserate, void (*callback_function)());
int _tmain(int argc, _TCHAR* argv[])
{
TIM_Enable(Rate_62_5ns,prnt0);
while(1);
return 0;
}
void TIM_Enable(Baserate my_baserate,void (*callback_function)())
{
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是为什么相同的 enum Baserate 在控制台应用程序中有效,但在嵌入式程序中无效。
在 C 中,您需要使用 typedef enum Baserate {/*your values here as before*/} Baserate;
这是 C 和 C++ 之间的细微差别之一。