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

Mark K. Kim markslist at cbreak.org
Sun Aug 26 18:17:01 PDT 2001

On Sun, 26 Aug 2001, Rainer Deyke wrote:

> Integral promotion rules.  In 'x << 8', the right-hand side is of type
> 'int', so the left hand side is promoted also promoted to 'int'.  There is
> also a rule that in any expression, all types narrower than 'int' are
> promoted to 'int'.

Hmm... I don't think we can assume "int" is as big as Int32, can we?  
Perhaps the code should read:

   return (Int32)p[2]<<a | (Int32)p[1]<<b | (Int32)p[0];

instead of:

   return p[2]<<a | p[1]<<b | p[0];


Furthermore, I believe "|" is higher on the order of operations than "<<",
so don't we actually want:

   return ((Int32)p[2]<<a) | ((Int32)p[1]<<b) | (Int32)p[0];


-Mark (on a high latency shell connection from Japan to US...)

Mark K. Kim
PGP key available upon request.

More information about the SDL mailing list