Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* is gethostsex standard?
@ 2001-10-04 12:26 nullepart
  2001-10-04 14:10 ` Bob Harris
  0 siblings, 1 reply; 2+ messages in thread
From: nullepart @ 2001-10-04 12:26 UTC (permalink / raw)


Hi,

I'm trying to write some code which handles big-endian and little-endian
byte ordering.  I've tried to check which one it is by checking the
definition of BIG_ENDIAN and LITTLE_ENDIAN, but i've found that they are
both defined.

I thought about using gethostsex, but I'm getting the impression that
this is tru64-unix-specific.  That doesn't seem right to me because the
whole reason for checking is so i can write cross-platform code.

Any help would be appreciated.

thanks



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: is gethostsex standard?
  2001-10-04 12:26 is gethostsex standard? nullepart
@ 2001-10-04 14:10 ` Bob Harris
  0 siblings, 0 replies; 2+ messages in thread
From: Bob Harris @ 2001-10-04 14:10 UTC (permalink / raw)


[[ 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-10-04 14:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-04 12:26 is gethostsex standard? nullepart
2001-10-04 14:10 ` Bob Harris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox