"Michael Mair" <Mi**********@i nvalid.invalid> wrote in message
news:37******** *****@individua l.net...
Mabden wrote: "Michael Mair" <Mi**********@i nvalid.invalid> wrote in message
news:36******** *****@individua l.net...
>>char teststr[100] = {0};
>
>This one does not do the same thing. This one initializes the
entire>array to zeros.
infobahn is right, gooch is wrong.
To clarify that: C99, 6.7.8#20 (Initializers)
"If there are fewer initializers in a brace-enclosed list than there
are
elements or members of an aggregate, or fewer characters in a string
literal used to initialize an array of known size than there are
elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage
duration."
That is, the second behaviour gooch was talking about (rest
initialised
to zero) is always what we can expect.
What does this do:
char teststr[100] = {1,2,3};
Does teststr now have 1, 2, 3 then 97 zeros? Or 1, 2, and 98 threes?
Or what?
Think hard, mock elsewhere.
I was not mocking, this time.
Hint: Integer variables of static storage duration without an explicit
initialiser are initialised to 0, for arrays this applies elementwise.
I was wondering if the array is initialized with the last value or zero.
Actually I meant to add a third option (Does is init with
1,2,3,1,2,3,1,2 ,3,1,2,3 for the size of the array?) but I posted too
quickly and saved myself some embarrassment.. . ooops!
I thought the standard might have meant that it would take whatever
partial initializers it was given and propagated them to the entire
array. But it seems it actually treats it like an automatic variable and
fills with zeros.
I live and learn from all your wonderful insights.
--
Mabden