This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: designated initializers extension and sparc


> 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, however it fails on
> the sparc.
> What the problem with the test?

Type punning through union is actually the preferred way to expose endianness.
Ask yourself how the 'int' and the 'double' are laid out on the SPARC.

-- 
Eric Botcazou


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]