Unspecified Bounds Error When an Array is Passed to a Macro
I have done some experimenting and I believe I understand what has happened here. The source of the error is this part of the macro:
&AR+1
This would work if the compiler knew the size of the array AR. Although the global arrays passed as AR are static, and their fixed sizes are known at compile time, they are defined in a .c file other than the ones this macro is expanded in. All the compiler has to go by is the declaration in the header which does not now have size information.
For the same reason the sizeof operator gets the same error &AR+1 does. It appears this macro has no advantage over using the sizeof operator this way:
#define ARSIZE(AR) sizeof(AR)/sizeof(*AR)
Earlier I attempted to define the size and initial contents of the array in the header. I got errors. Should it be possible to do this? An example syntax I used in the header is:
extern int arr = { 1, 2, 3, 4, 5 };
The error was these arrays were being defined more than once, in spite of using the typical compiler directive ifndef to assure that everything is declared only once, and the first time the header is included.
I am seeking to ease code maintenance and reduce opportunities for the code to be accidentally broken later should these array size be changed latter. I want the compiler or code execution to determine number of elements in these arrays, and do it with as few variables or macros as possible.