Subject: hto{le,be}{16,32,64}() proposal
To: None <>
From: Simon Burge <>
List: tech-userlevel
Date: 06/25/1999 21:54:09
Here's "Plan B", after htonq() and ntohq()...

We need a scheme where we can specify a data format that's independant
of the endianess of the machine.  Todd points out that hton?() and
ntoh?() are intended for network data, and we still don't know what
format is big- or little-endian without an #ifdef test.

I propose adding a set of macros to <machine/bswap.h> called
htole{16,32,64} and htobe{16,32,64} implemented in terms of bswap* and
no-ops.  There would also be a matching group of {le,be}toh* which do
exactly the same thing.

I'm not 100% convinced that <machine/bswap.h> is the right place for
these.  I'd be happier putting these in <machine/endian.h>, but then
that header file would have to include <machine/bswap.h> to get the
bswap* prototypes.  Would doing this break anything?

In a previous thread on tech-kern, the names hto{b,l}* and {b,l}toh*
were suggested.  To me, these aren't descriptive enough.  Comments on