R
Richard Tobin
No. To determine endianness, you have to dereference the same address
as each of two different types, so a cast is quite natural. You could
do it with a union instead.
Was that something that changed in C99? C89 says,
3.3.2.3 Structure and Union Members
[...]
With one exception, if a member of a union object is accessed after
a value has been stored in a different member of the object, the
behavior is implementation-defined.[/QUOTE]
Yes, it's implementation-defined. Typically the implementation will
define reading an int as an array of char to read the bytes of the int
in some order, known as the byte order
*Any* test of endianness is bound to use implementation-defined or
undefined behaviour, otherwise all machines would be found to have the
same endianness!
-- Richard