Considering the VLA (variable length array), I would like to ask your opinion on the following problem: If the array is defined in the global scope in one file:
int arr[] = {1, 2, 3};
#define arr_num sizeof(arr)/sizeof(arr[0])
enum {arr_num = sizeof(arr)/sizeof(arr[0])};
The problem is that in other files in the same project, I would like to again create other arrays in the global area with the same number of elements as in the arr. But how can this be achieved in C99 if there is no way to "extern" enum or #define. Of course, you can # determine the number of arr elements manually in the header file, and then use it in other files, but this is very inconvenient, since changing the number of elements in the arr array, you also need to manually change the value of this #define (this is even more inconvenient when arr is an array of structures).
Thanks so much for any help.
source
share