Subject: Re: hto{le,be}{16,32,64}() proposal
To: Simon Burge <simonb@netbsd.org>
From: Julian Assange <proff@iq.org>
List: tech-userlevel
Date: 07/25/1999 06:08:17
Simon Burge <simonb@netbsd.org> writes:

> 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
> this?
> 
> Simon.

No need to reinvent what is really an arbitrary wheel. There's no "right"
solution here, so instead try and find one that has already been
adopted. Does linux, freebsd, osf, solaris etc have a convention?

Julian.