tech-misc archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Endian-specific types
>> ive toyed with the idea of making types like this: [...endianness...]
Much of the problem with endian-specific types is that - at least in C,
and I think in C++ - types describe values, and endianness is not a
property of a value; it's a property of a value as serialized into an
octet (or other unit smaller than the value) stream. It does not make
sense to talk about the endianness of a value in a CPU register, any
more than it makes sense to talk about the bit-endianness of a byte in
memory (unless the machine supports bit addressing or otherwise imposes
some ordering on the bits within a byte).
Thus, wanting endian-specific types indicates that you're doing
something wrong: you're confusing a value with its serialization.
There is a lot of history behind creating octet streams (typically for
network protocols) by overlaying structs onto byte buffers - and I
believe it is misled, all of it; the correct thing to do is to work
with values as values and then explicitly convert between the values
and their serializations, and it is at that conversion step, and *only*
at that conversion step, that endianness has any business getting
involved. (Doing it that way also inherently fixes a whole bunch of
alignment bugs waiting to happen.)
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index