tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Endian-specific types



> On Sep 7, 2016, at 9:28 PM, David Gwynne <david%gwynne.id.au@localhost> wrote:
> 
> ...
> ive toyed with the idea of making types like this:
> 
> typedef struct {
>  uint16_t word;
> } __le16;
> 
> typedef struct {
>  uint16_t word;
> } __be16;
> 
> and an api like this:
> 
> uint16_t lemtoh16(__le16 *src);
> uint16_t bemtoh16(__be16 *src);
> void htolem16(__le16 *dst, uint16_t src);
> void htobem16(__le16 *dst, uint16_t src);
> 
> you can assign structs to other structs of the same type by value, which is pretty natural for the above. however, it forces you to go via an api to do actual loads and stores.

Too bad we don't use C++.  I did roughly what you described 20 years ago, but in C++ using type conversion methods to go through those conversion operations automatically.

	paul



Home | Main Index | Thread Index | Old Index