The first statement creates a variable initialized with the given values, i.e. these values are built in memory and stored directly in executable software at this variable address (for global) or are ready to copy memory (for stack variables).
The second statement of the second block is very different. Although it looks similar, it is an expression of purpose. This means that the RHS of the equals operator is an expression that is evaluated (regardless of what is in LHS = =) and then passed to the = operator. Without the proper context, {...} is irrelevant.
In C99, you can do this:
struct_name_id = (struct struct_type_id){ value1, value2, value3 };
Now the RHS of the equals operator is a valid expression, because there is an appropriate context for the compiler to find out what is in {...} .
In C ++ 11, the syntax is:
struct_name_id = struct_type_id{ value1, value2, value3 };
Juliano Nov 10 '09 at 1:45 2009-11-10 01:45
source share