0

I have the following file structure

service.h
config.h
config.c

In the service.h file a struct serviceStruct is declared with one member a unsigned int.

I declare an array of serviceStructs in the file config.h and in the config.c file, I initialize the members.

Now I get the error array type has incomplete element type

How can i solve this error?


[update from comment:]

service.h:

typedef uint32_t board_spi_select_id_t;

struct spi_device
{ //! Board specific select id 
  board_spi_select_id_t id;
};

config.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];

config.c:

#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 } 
};
6
  • 2
    Please show a bit more context; pehaps an include is missing somewhere? Commented May 8, 2014 at 7:29
  • show us the declaration of array of struct serviceStructs in the file config.h Commented May 8, 2014 at 7:31
  • the struct declaration in the service.h typedef uint32_t board_spi_select_id_t; struct spi_device { //! Board specific select id board_spi_select_id_t id; }; the config.h file #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]; the config.c file #include config.h spi_device_t spi_ss_id[4] = {{SPI_SS_ADF4350_C1}, {SPI_SS_ADF4350_C2},{ SPI_SS_AD9854_C1},{SPI_SS_AD9854_C2}}; Commented May 8, 2014 at 8:05
  • Cant post is as an answer no reputation Commented May 8, 2014 at 8:06
  • 1
    Do not significantly change your question after answers had been posted, as those edits might make certain answers un-understandable. Just add more to your answer without deleting what there was. Commented May 8, 2014 at 11:08

2 Answers 2

2

In config.c

spi_device_t 

is unknown.

Either use struct sp_device instead of spi_device_t

struct spi_device spi_ss_id[4] =  
{
  ...

or declare the latter, for example by adding

typedef struct spi_device spe_device_t;

at the end of service.h.

Sign up to request clarification or add additional context in comments.

4 Comments

So include service.h in config.h (and not in the main program).
@Jongware That's what the OP seems to be doing.
Ah, you're right -- I got lost in the order of includes and defines. spi_device_t is simply not defined anywhere. gcc reports error: expected specifier-qualifier-list before 'board_spi_select_id_t'
@alk Sorry, it was copied wrong, I used both methods you described but without succes. The error array type has incomplete element type hits on the line where i define the the array in my header file. I edited the original post. When i declare the the array only in the config.c file it compiles without error. So i dont think its an include problem
0

You are defining SPI_SLAVE_COUNT, but in the array definition you use SPI_SLAVE_CNT - notice the different spelling.

If I change this, it compiles fine for me with both gcc and clang.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.