Re: User level Macros for Endianess

From
David A. Gatwood <hidden>
Date
2000-01-12 19:37:17
On Wed, 12 Jan 2000 iweiny@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/
Thread (1 message) 1 message, 1 author, last reply 2000-01-12
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help