This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Array initialization inside struct

Hello,
I try compile this code (.c) with --c99 option

struct sx { char c; char a[];
};
static struct sx xx = { 1, {[5] = 0} };

and have error
error: #146: too many initializer values

How to initialize array inside struct ?

ARM C/C++ Compiler, 4.1 [Build 791] [Standard]

Thanks

Parents
  • May be nut this code compiled under GCC.

    Well, GCC has a history of non-trivial language extensions, so this shouldn't be surprising.
    To me the question is: what is the expected size of the array in the structure xx? I cannot see a satisfactory answer to this question, so to me it is natural that C99 (as per the text of the C99 standard) does not allocate any memory for the array and does not expect an initializer for the array.

Reply
  • May be nut this code compiled under GCC.

    Well, GCC has a history of non-trivial language extensions, so this shouldn't be surprising.
    To me the question is: what is the expected size of the array in the structure xx? I cannot see a satisfactory answer to this question, so to me it is natural that C99 (as per the text of the C99 standard) does not allocate any memory for the array and does not expect an initializer for the array.

Children