我正在尝试初始化下面的结构,称为 arduino_lcd_t
。因为我使用的外设可以一次写入四位数据,也可以一次写入八位数据,所以我决定使用一个宏来相应地定义自己。但是,我无法编译此代码,可能是因为 #ifdef
的宏。我收到警告
declaration does not declare anything
是我哪里做得不对,还是不能这样做?相关代码如下。
#define FOUR_BIT_MODE 1
#ifdef FOUR_BIT_MODE
#define DATA_LEN 4;
#else
#define DATA_LEN 8
#endif
typedef struct
{
long lighting_pin;
long register_select_pin;
long read_write_pin;
long enable_pin;
**long data_pins[DATA_LEN];**
} arduino_lcd_t;
最佳答案
long data_pins[DATA_LEN];
当宏被扩展时,它将变成
long data_pins[4;];
4;
不能是数组的索引。删除宏末尾的 ;
关于c - 无法使用 ifdef 宏初始化结构内部的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41774549/