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

Mattias Engdegård f91-men at nada.kth.se
Thu Aug 30 08:30:01 PDT 2001

"John R. Hall" <overcode at lokigames.com> wrote:
>Again, it's a bad assumption that seems to work on most platforms. It will 
>probably fail on platforms where sizeof(int) != 4 or (possibly) the 
>compiler isn't gcc. I had big problems with this when I tried to port SDL 
>to PalmOS (finally did get it to compile without warnings after adding a 
>bunch of Uint32 casts to this kind of code).

read the section about integral promotion in the standard. If you have
had it "fail on some platforms", and it is SDL code, then please
notice us so we can check if it needs to be fixed

In this case the code makes the silent assumption that an int is at least
24 bits in size, which is mostly true for the platforms SDL was intended
to run on but since the Standard allows int to be as small as 16 bit
it is not strictly correct (widening cast is needed)

I suspect the SDL code itself trusts int to be at least 32 bits in a lot
of places (and perhaps a couple where int is assumed to be *exactly*
32 bits, although I have tried to minimize that myself

Sometimes compilers for 16-bit platforms allow you to specify via option
flags whether int should be 16 or 32 bit. This is especially useful
for a 16-bit implementation of a 32-bit architecture like the m68000

More information about the SDL mailing list