简体   繁体   中英

C: array type has incomplete element type error for external array

In file "cerberOS_BSP.h" I have the following:

extern char cmp_ids[][];
extern UInt8 periph_list[];

In file "BSP_unpnp.c", I have:

UInt8 periph_list[AMOUNT_OF_PERIPH] = {0};
char cmp_ids[MAX_CMPS][4] = {0};

This gives no errors for periph_list but gives the following for cmp_ids:

../../uJ/cerberOS_BSP.h:55:13: error: array type has incomplete element type
 extern char cmp_ids[][];

Unsure on how to solve this since I don't fully understand the issue, any ideas?

In the case of …

char cmp_ids[][];

… you have two dimensions with open (unspecified) size. Since the location of an element is calculated by start + index * sizeofelements , it is necessary to know the size of the elements.

The element of the outer array is the inner array char[] . The size is not known.

You can only omit the most outer size. All other sizes have to be specified.

An array must be declared with a size, for instance:

extern char cmp_ids[MAX_CMPS][4];
extern UInt8 periph_list[AMOUNT_OF_PERIPH];

Therefor, in the header file you need to add (or include) the definitions of MAX_CMPS and AMOUNT_OF_PERIPH. If the sizes need to be calculated at run-time you can instead use pointers:

extern char **cmp_ids;
extern UInt8 *periph_list;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM