D
Derrick Coetzee
Looking through the C90 standard, it occurred to me that the possible
syntaxes for initializers, particularly of wchar_t arrays, are really
bizarre. Consider the following:
wchar_t s1[] = { L"abcdef" };
wchar_t* s2[] = { L"abcdef" };
wchar_t s3[][6] = { L"abcdef" };
wchar_t* s4[][6] = { L"abcdef" };
That's four different types initialized with exactly the same
initializer syntax, but it means four different things. In the first
case, a mutable buffer is being initialized, and the standard lets you
wrap the string intializing the buffer in braces for no apparent reason.
In the second case, an array containing one pointer to a literal string
is declared. In the third case, an array containing one initialized
mutable buffer is declared. In the fourth case, a 1 by 6 two-dimensional
array is declared, with s4[0][0] set to a literal string, and s4[0][1]
through s[0][5] set to a null pointer. I could continue with
larger-dimensional arrays right up to the environment limits.
Thoughts?
syntaxes for initializers, particularly of wchar_t arrays, are really
bizarre. Consider the following:
wchar_t s1[] = { L"abcdef" };
wchar_t* s2[] = { L"abcdef" };
wchar_t s3[][6] = { L"abcdef" };
wchar_t* s4[][6] = { L"abcdef" };
That's four different types initialized with exactly the same
initializer syntax, but it means four different things. In the first
case, a mutable buffer is being initialized, and the standard lets you
wrap the string intializing the buffer in braces for no apparent reason.
In the second case, an array containing one pointer to a literal string
is declared. In the third case, an array containing one initialized
mutable buffer is declared. In the fourth case, a 1 by 6 two-dimensional
array is declared, with s4[0][0] set to a literal string, and s4[0][1]
through s[0][5] set to a null pointer. I could continue with
larger-dimensional arrays right up to the environment limits.
Thoughts?