[comp.lang.c] Portability vs. Endianness, an official answer

dold@mitisft.Convergent.COM (Clarence Dold) (03/15/91)

in article <Nogsy1w164w@ersys.uucp>, ersys!markt@nro.cs.athabascau.ca (Mark Tarrabain) says:

> this is slightly machine dependant - it assumes that the size of a long

Why not get really machine dependent?  Let the vendor do it for you.

If you have networking, you should have routines to put and fetch
'network byte order' values, BYTEORDER(3N).
There are macros htonl, ntohl, etc, for converting to/from host style to 
network style.

Snoop around for in.h.  On our Motorola box, it is a noop.
On the Intel box, it is some in-line assembly.

(I don't really dispense official answers, but I thought it was a catchy
change to the subject line...)
-- 
---
Clarence A Dold - dold@tsmiti.Convergent.COM
               ...pyramid!ctnews!tsmiti!dold