From: Bob Harris <harris@zk3.dec.com>
Subject: Re: is gethostsex standard?
Date: Thu, 04 Oct 2001 10:10:49 -0400 [thread overview]
Message-ID: <041020011010493946%harris@zk3.dec.com> (raw)
In-Reply-To: 3BBC558C.D58DB75C@voila.fr
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <3BBC558C.D58DB75C@voila.fr>, nullepart
<driveblind@voila.fr> wrote:
X Hi,
X
X I'm trying to write some code which handles big-endian and little-endian
X byte ordering. I've tried to check which one it is by checking the
X definition of BIG_ENDIAN and LITTLE_ENDIAN, but i've found that they are
X both defined.
X
X I thought about using gethostsex, but I'm getting the impression that
X this is tru64-unix-specific. That doesn't seem right to me because the
X whole reason for checking is so i can write cross-platform code.
Try a simple bit of 'C' code:
union {
short s;
char c[2];
} endian;
endian.s = 1;
if ( endian.c[0] == 1 )
printf( "Little Endian\n" );
else
printf( "Big Endian\n" );
Also, I looked at some examples of BIG_ENDIAN and LITTLE_ENDIAN use,
and it seems the correct way to use it is to say:
if ( BYTE_ORDER == LITTLE_ENDIAN )
printf( "Little Endian\n" );
else
printf( "Big Endian\n" );
Bob Harris
Bob Harris
prev parent reply other threads:[~2001-10-04 14:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-04 12:26 is gethostsex standard? nullepart
2001-10-04 14:10 ` Bob Harris [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox