On Mon, Jun 17, 2013 at 01:28:56AM +0300, Sergey Kljopov wrote:
> Hi,
>
> Reading the text
> -------------
> In a structure initializer, specify the name of a field to
> initialize with `.fieldname =' before the element value. For
> example, given the following structure,
> struct point { int x, y; };
> the following initialization
> struct point p = { .y = yvalue, .x = xvalue };
> is equivalent to
> struct point p = { xvalue, yvalue };
> Another syntax which has the same meaning, obsolete since GCC 2.5,
> is `fieldname:', as shown here:
> struct point p = { y: yvalue, x: xvalue };
> The `[index]' or `.fieldname' is known as a designator. You can also
> use a designator (or the obsolete colon syntax) when initializing a
> union, to specify which element of the union should be used. For
> example,
> union foo { int i; double d; };
> union foo f = { .d = 4 };
> will convert 4 to a double to store it in the union using the second
> element. By contrast, casting 4 to type union foo would store it
> into the union as the integer i, since it is an integer. (See Cast
> to Union.)
> -------------
> I wrote the following test:
>
> union foo { int i; double d; };
>
> int main(int argc, char **argv)
> {
> union foo f = { .d = 4 };
>
> ASSERT_EQ(0, f.i);
> ASSERT_FEQ(4.0, f.d);
>
> return 0;
> }
>
> ASSERT_EQ and ASSERT_FEQ are some macros which checks the falue and
> gives some error messages.
>
> It seems that this extension should be bi-endian,
It is not. But this is off-topic on this mailing list, which is about
the development of the compiler, not using it.
Please try gcc-help instead.
Gabriel