[SDL] Get pixel value ...more in details

Kylotan kylotan at kylotan.eidosnet.co.uk
Sun Aug 26 08:18:01 PDT 2001


> I understand a little more...but:
>
> - shifting one bite by 16 or even 8 bits doesn't always gives
>  a zero value ?

It probably should. But apparently doesn't. I am guessing that this code
relies on implementational details, such as the compiler always
implicitly using 32 bits (or more) for temporary values of bytes. And
that this could break if the compiler chose to do it differently. But no
doubt someone will quote a paragraph from the standard explaining why I
am wrong. If you're worried about it, put a (Uint32) cast before the
p[2] in the expression.

> - we are returning p[2]<< a | p[1] << b | p[0] that is not*
> a Uint32 (also *p or *(Uint16 *)p are not) , so how and where
> happens this conversion ??

The conversion is automatic (implicit). The compiler can perform this
kind of conversion automatically because you can't possibly lose any
data casting up from one integral type to a larger integral type. So no
cast is needed.

--
Ben Sizer





More information about the SDL mailing list