Re: Question on byteorder operations
From: Gordon Burditt (gordonb.asxh4_at_burditt.org)
Date: 03/22/05
- Next message: Keith Thompson: "Re: Question on byteorder operations"
- Previous message: Yuri Shtil: "interrupted system call in parallel gnumake on solaris."
- In reply to: usenet_at_sta.samsung.com: "Question on byteorder operations"
- Next in thread: Keith Thompson: "Re: Question on byteorder operations"
- Reply: Keith Thompson: "Re: Question on byteorder operations"
- Reply: CBFalconer: "Re: Question on byteorder operations"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Mar 2005 20:03:05 GMT
>My experience has been that **ON A GIVEN SYSTEM** htonl and ntohl
>always evaluate to the same thing ----- either both of them are no-op
>or both of them swap the bytes of the long value that is passed. [Of
>course, as you go from a big-endian system to a little-endian system,
>the behavior will be different, but that is not what I am talking
>about] Same for htons and ntohs.
>
>Can I generalize my observation, or are there any exceptions?
It is *POSSIBLE* that there are exceptions, but I don't know of any
on real systems. ANSI C certainly allows such byteorders (but it
doesn't specify htonl() and ntohl() at all).
There are 8 possible byte orders for sizeof(int) == 3. For those
3 combinations which are not a byte-swap of pairs of specific bytes
nor a noop (123 -> 312, 123 -> 321, 123 -> 231), htonl(x) == ntohl(x)
will be false for some value of x.
There are 24 possible byte orders for sizeof(int) == 4. I haven't
worked out how many combinations make htonl() and ntohl() operate
differently, but one of them would be 1234 -> 2341.
Gordon L. Burditt
- Next message: Keith Thompson: "Re: Question on byteorder operations"
- Previous message: Yuri Shtil: "interrupted system call in parallel gnumake on solaris."
- In reply to: usenet_at_sta.samsung.com: "Question on byteorder operations"
- Next in thread: Keith Thompson: "Re: Question on byteorder operations"
- Reply: Keith Thompson: "Re: Question on byteorder operations"
- Reply: CBFalconer: "Re: Question on byteorder operations"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]