On Mon, Jun 17, 2013 at 4:21 AM, Sergey Kljopov <hlodvig@xxxxxxxxx> wrote: > > 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? I'm sorry, I don't understand your question. You're right, SPARC is big-endian where x86 is little-endian, so if you look at the first four bytes of a double you will get different results on the two systems. That is all normal and expected behaviour. I think you neglected to explain what you actually want to do. Ian