designated initializers extension and sparc

Sergey Kljopov hlodvig@unipro.ru
Mon Jun 17 11:21:00 GMT 2013


I tried to ask in gcc and was redirected here.

So, I've read the spec about extension

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.)

and 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 value and
gives some error messages.

But it fails on sparc. I guess int should be equal 0x40100000 since bytes are in reverse order.
As I know now, this extension is not bi-endian.
So the question is: what shall I do? Does it mean that I just shall forget about that extension usage on sparc?

Sergey



More information about the Gcc-help mailing list