Re: [AD] shiftoperators (was: improvements on alphablending...)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, Aug 03, 2001 at 01:13:13AM +0200, Evert Glebbeek wrote:
> Well, my concern was something like this: how do you know that shifting to
> the right corresponds to deviding by 2? I don't know of such machines, but
> it would be possible that there are machines that have the low bit at the
> *left* of a word, so that the 8 bit number 01000000 would be equal to 2
> instead of 64?

Because the C standard defines it that way.  Shifting a positive
integer n places right (n < number of bits in an int)
corresponds to dividing by 2^n, and shifting left corresponds to
multiplying by 2^n (ignoring overflow).  Shifting negative
integers right is unportable (implementation-defined), and
shifting by negative amounts or amounts not less than the width
of the int is undefined.

> Also, couldn't it give incompatibel code between little endian/big endian
> encodings?

Endianness is a totally different issue, only relating to how
multibyte quantities are stored in memory.  Shifting occurs on
the CPU.

> Anyway, I usually try to avoid shift operators if I want my code to run at
> my PC as well as a SUN workstation. Am I over cautious?

Yes.

George



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/