User level Macros for Endianess
David A. Gatwood
dgatwood at deepspace.mklinux.org
Thu Jan 13 06:37:17 EST 2000
On Wed, 12 Jan 2000 iweiny at pacbell.net wrote:
> Unfortunately I don't have an x86 Linux machine and he has been reluctant to
> change his code because he feels this is not the "proper" way to detect
> endianess across Linux's, Solaris, and possibly other UNIX's.
Well, if you really want it to be completely cross-platform, you could do
something like:
int a = 0x33323130;
char *b, d[5];
int c;
for (b=(char *)&a, c=0; c<4; c++,b++)
{
d[c]=*b;
}
d[5]=0;
I believe that the Linux macros do this same basic thing, if memory
serves.... BTW, if you printf("%s", d) you'll get 3210 on big endian,
0123 on little. You could also do it as short integers instead of
characters by subtracting 48 in the d[c]=*b line.
Just a sick thought. :-)
Later,
David
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
More information about the Linuxppc-dev
mailing list