And this works in C:
int main (void)
{
const char s7[7] = "1234567";
return 0;
}
I don't follow at all what he thinks the type of the initalizer has to
do with anything.
Well, apparently it doesn't have anything to do with it for char arrays.
Try initializing an object with the wrong type for most other things though
an you will have a problem. Anyway, I finally did what I should have done
to begin with and looked it up in the standard. In [dcl.init.string]/1-2
it says:
1. A char array (whether plain char, signed char, or unsigned char)
can be initialized by a stringliteral (optionally enclosed in
braces); a wchar_t array can be initialized by a wide stringliteral
(optionally enclosed in braces); successive characters of the
stringliteral initialize the members of the array.
[Example:
char msg[] = "Syntax error on line %s\n";
shows a character array whose members are initialized with a
stringliteral.
Note that because ’\n’ is a single character and because a trailing
’\0’ is appended, sizeof(msg) is 25. ]
2 There shall not be more initializers than there are array elements.
[Example:
char cv[4] = "asdf"; // error
is illformed since there is no space for the implied trailing ’\0’.
]
So, for whatever it's worth, they seem to consider a string literal to be
null terminated and refuse to let the compiler do the truncating for you.
joe