That's how the C language is works, the compiler just does not know the size when only the declaration without size is known.
As possible solutions you could:
- specify the array size in the declaration:
main.h:
extern const Byte array1[14];
The disadvantage is obviously that you have to maintain the array
size explicitly. The compiler will check the size at least when he
sees the declaration and the definition while compiling main.c
(say when the extern declaration is in main.h)
-define another constant with the size.
main.h:
extern const Byte array1[];
extern const size_t array1_size;
#define ARRAY_SIZE array1_size
main.c:
#include "main.h"
const Byte array1[] = "Sample";
const size_t array1_size = sizeof(array1);
The disadvantage here is that the code is a little bit less efficient
as the array size is no longer known at compile time, but has to be
actually read from a constant at runtime instead.
Daniel