Seebs said:
When array size specified conflicts the initializer e.g.:
char s[5] = "0123456789";
A quick test with a random compiler at hand shows that it reserves space for
11 chars, but what does the standard say about it?
* If the string is shorter than the specified size of the array,
it is padded with '\0'.
Not 'string', as strings already have a '\0' at the end:
7.1.1 Definitions of terms
[#1] A string is a contiguous sequence of characters
terminated by and including the first null character. The
You should probably use '[character] string literal' instead.
Usage of that term includes:
[#5] In translation phase 7, a byte or code of value zero is
appended to each multibyte character sequence that results
from a string literal or literals.
So a 'string literal' does not yet necessarily have the '\0' at the end.
(And may contain embedded '\0' characters too, which a string can not.)
And I can't say I like 'pad' either. That implies some kind of
resizing to fit. The NIL's just appended, nothing more.
* If the string is exactly the size of the array, the array is populated
with the contents of the string.
* If the string (including the terminator) is exactly one character larger
than the array, the bytes from the string are stored in the array, and
the array is not NUL-terminated.
* If the string is larger than the array, the compiler is supposed to
give you a diagnostic, after which it may do anything it wants.
I think it's best to just drop references to 'string', they confuse
matters.
In fact, it's hard to just beat the elegance of the original:
[#14] 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.
+
[#2] No initializer shall attempt to provide a value for an
object not contained within the entity being initialized.
Phil