Hi,
I'm struggling with getting the size of a const array with undefined size. The array is defined in a .c file which is not the main .c file. See code:
// In separate.c file (listed in makefile): const char ConstArray[]={2, 3, 5, 7, 11}; // In separate.h file (included in separate.c and main.c): extern const char ConstArray[]; // In main.c file: if (memchr(ConstArray, Blah, sizeof(ConstArray)))
The above approach doesn't work, and I don't know why. I get the "invalid application of 'sizeof' to incomplete type 'const char[]' " error.
To fix it, I can either set a defined size (in this case 5) of the array, or I can move the definition of the array into the main.c file.
// In separate.c file (listed in makefile): const char ConstArray[5]={2, 3, 5, 7, 11}; // In separate.h file (included in separate.c and main.c): extern const char ConstArray[5]; // In main.c file: if (memchr(ConstArray, Blah, sizeof(ConstArray))) or // In main.c file: const char ConstArray[]={2, 3, 5, 7, 11}; if (memchr(ConstArray, Blah, sizeof(ConstArray)))
Can anybody explain why?
µCtlr: ATmega1281
Compiler version: 20100110
Best regards,
ErikT