Re: bitops and endianness

Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
Thu, 5 Feb 1998 18:17:48 +0100 (CET)


On Wed, 4 Feb 1998, Benjamin C.R. LaHaise wrote:
> On Wed, 4 Feb 1998, Geert Uytterhoeven wrote:
> > Wouldn't it be better to declare the bitops to take a pointer to an unsigned
> > long, instead of a void *? Then we would at least get a warning when a little
> > endian guy does bitops on a char.
>
> Hmmm? But bitops are valid on a char - they're defined to work in little
> endian fashion across all platforms, hence there shouldn't be a problem.
> Besides, if the caller specifies an out-of-range bit offset, memory will
> get overwritten, and there's nothing that can be done about it.

I checked with some people and they disagree: bitops are defined to work in the
native order of the CPU.

This means that bitops on anything less than a long (valid on 32 and 64 bit
CPUs) are invalid.

Greetings,

Geert

--
Geert Uytterhoeven                     Geert.Uytterhoeven@cs.kuleuven.ac.be
Wavelets, Linux/{m68k~Amiga,PPC~CHRP}  http://www.cs.kuleuven.ac.be/~geert/
Department of Computer Science -- Katholieke Universiteit Leuven -- Belgium