Strangeness with SDL_SetColorKey

In the test program “testalpha”, the designated way to set a loaded
image’s colorkey based on pixel at (0,0) is:

SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *)temp->pixels );

However, when I tried it, it didn’t work.

But this did work:

Uint32 key;
memcpy( &key, temp->pixels, temp->format->BytesPerPixel );
SDL_SetColorKey(temp, SDL_SRCCOLORKEY, key );

Any ideas why the first way (which is the way shown in the example
program) doesn’t work? I’m just wondering.

// joey tsai

Please CC to me.–
| PITIFUL, adj. The state of an enemy of opponent after an
joey tsai | imaginary encounter with oneself.
| – Ambrose Bierce, “The Devil’s Dictionary”

SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *)temp->pixels );

However, when I tried it, it didn’t work.

But this did work:

Uint32 key;
memcpy( &key, temp->pixels, temp->format->BytesPerPixel );
SDL_SetColorKey(temp, SDL_SRCCOLORKEY, key );

#include <stdio.h>

int main(void)
{
unsigned int x1 = 0x439432FF;
unsigned int x2 = 0x439432FF;
unsigned char ch = 5;
memcpy(&x1, &ch, sizeof (ch));
x2 = ch;
printf(“memcpy’d from different size types: %ld\n”, x1);
printf(“compiler casts/assigns between different size types: %ld\n”, x2);
return(0);
}

–ryan.