小编Chr*_*iki的帖子

在定义预处理程序语句中使用括号

所以我想知道什么时候使用

 #define xxx (yyy)
Run Code Online (Sandbox Code Playgroud)

VS

 #define xxx  yyy
Run Code Online (Sandbox Code Playgroud)

我的项目包括一个在AD0_ADMD_CT上有自己定义的文件,如果我想重新定义它们,我需要在定义中使用(AD0_ADMD_CT)或AD0_ADMD_CT吗?

AD0_ADMD_CT定义为

 #define    AD1_ADMD_CT     (IO_AD1.ADMD.bit.CT)
Run Code Online (Sandbox Code Playgroud)

所以它也是

#define AD0_COMPARETIME     (AD0_ADMD_CT)
Run Code Online (Sandbox Code Playgroud)

要么

#define AD0_COMPARETIME     AD0_ADMD_CT
Run Code Online (Sandbox Code Playgroud)

c c-preprocessor

5
推荐指数
2
解决办法
2998
查看次数

标识符枚举未定义

好的,我看到这是一个相当普遍的问题,但我找不到与我的问题类似的问题。

我不断遇到问题

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)

所以我的问题是为什么相同的 …

c

0
推荐指数
1
解决办法
5539
查看次数

标签 统计

c ×2

c-preprocessor ×1