On 11/2/2011 9:30 AM, MJ_India wrote:
> C++ file with following code compiles without any complaint on GCC and
> Microsoft Visual C++.
>
> int main() {
> int something = {42}; // 1. LOC that makes me sick
> // something = something; // To silent unused variable warning
> }
>
> {...} seems perfect for initialization for a structure or an array.
> My question is; why is it valid to initialize an int with {42}?
> Sometimes I think it is okay, but some other time this is confusing.
> Please help.
>
> Microsoft Visual C++ also compiles the following lines without any
> complaints:
> 2. int weird[2] = {{{12}}};
> 3. int weirder = { { 3,} ,};
I think the curly braces are optional when writing the initialization of
a scalar variable. Commas are optional in some cases, but I am not sure
they are allowed in initializers; can simply be VC++ extension.
V
--
I do not respond to top-posted replies, please don't ask
|