我有以下文件结构
service.h
config.h
config.c
在 service.h
文件中,声明了一个 struct serviceStruct
,其中一个成员是 unsigned int。
我在文件 config.h
和 config.c
文件中声明了一个 array of serviceStructs
,我初始化了成员。
现在我得到错误array type has incomplete element type
我该如何解决这个错误?
[根据评论更新:]
服务.h:
typedef uint32_t board_spi_select_id_t;
struct spi_device
{ //! Board specific select id
board_spi_select_id_t id;
};
配置.h:
#include "service.h"
#define SPI_SLAVE_COUNT 4
#define SPI_SS_ADF4350_C1 0
#define SPI_SS_ADF4350_C2 99
#define SPI_SS_AD9854_C1 3
#define SPI_SS_AD9854_C2 99
struct spi_device ssid[SPI_SLAVE_CNT];
配置文件:
#include "config.h"
struct spi_device ssid[SPI_SLAVE_CNT] =
{
{ SPI_SS_ADF4350_C1 },
{ SPI_SS_ADF4350_C2 },
{ SPI_SS_AD9854_C1 },
{ SPI_SS_AD9854_C2 }
};
最佳答案
在config.c
spi_device_t
未知。
要么使用struct sp_device
代替spi_device_t
struct spi_device spi_ss_id[4] =
{
...
或声明后者,例如通过添加
typedef struct spi_device spe_device_t;
在 service.h
的末尾。
关于创建在另一个头文件中定义的结构数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535417/