[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Magic money not working bigendian



Try this:

--------------------------------------------
#include <stdio.h>

main()
{
	long t = 1 ;
	char *cp = (char *) & t  ;

	printf( "%s-endian\n", ( *cp != 0 ) ? "little" : "big" ) ;
}
--------------------------------------------

On a little-endian machine, the least significant byte is stored
first; on big-endian, the most significant.  The address of a long
points to the first byte, i.e. the byte with the lowest address.  The
above program tests to see if the first byte is non-zero, which is
true iff the length of a char is less than the length of a long
(usually true) and if the least significant byte is first, i.e.
little-endian.

Further responses should go only to my mailbox.

Eric