On 9 October 2012 17:13, Mans Rullgard mans.rullgard@linaro.org wrote:
This is what the C99 standard says:
An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.
In your case, the array will be initialised with the numbers 1-5, the null terminator of the string literal is ignored. Initialisers like this are fairly common and well-defined by the spec, so warning about them would be wrong IMHO.
Ahh.. My fault actually. I knew this stuff for any other array type, like int. If you initialize few fields of array, then the remaining are initialized with zero automatically.
And the same will hold for this one too... Because ascii value of '\0' is 0, so all the fields array elements, except the ones explicitly initialized with values will get initialized with 0 or '\0'. That's why the mystrcpy() routine written earlier by me will work (only if RHS string size is smaller than array size :) )
So, there is no overflow here at all. '\0' is just not there for this string and so printf("%s", ...) can show unexpected results.
-- viresh