On Mon, 31 Jul 2006 03:48:10 UTC, "joshc" <>
wrote:
> Hi,
>
> I have an array defined in one file with an intializer as follows:
>
> int arr[] = {0, 1, 2, 3};
This defines an array of 4 members. When the number of members defined
through the initialisers is too low you must define the real size to
get the list of initialisers expanded to the real number of members
you needs.
> I have a declaration of the array in another file as follows:
>
> extern int arr[10];
The best way would be:
insert the declaration into an header file and include it even on the
file you has to write the definition.
This will give the compiler the chance to extend the definition [] to
the size the declaration defines. On the other hand you can simply use
'extern int arr[]' in other translation units.
So 'int arr[ARR_SIZE] = { [incomplete] list of initialisers }; and
'extern arr[ARR_SIZE]' in a common header while ARR_SIZE describes the
size you needs really will give you in any place the chance to change
the arraysize only on one place.
> This compiles without a problem on my implementation and arr ends up
> being of size 10 on my implementation. Is this legal in "standard C"? I
> was reading question 1.24 of the FAQ but that didn't seem to answer my
> question in this case. Is the array definition with the initializer
> somehow an incomplete definition?
>
> Thanks for the help,
>
> Josh
>
--
Tschau/Bye
Herbert
Visit
http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!