32bit to 64bit c code errors
Author |
Message |
Zeroth
|
Posted: Fri May 01, 2009 7:54 pm Post subject: 32bit to 64bit c code errors |
|
|
Okay, so I'm trying to fix a bug in pygame, and I've experienced an interesting issue. The bug only occurs on 64 bit platforms, because of the extended size of the int/long.
c: |
//test_color.c
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
typedef uint8_t Uint8;
main ()
{
Uint8 r= 204;
Uint8 g= 0;
Uint8 b= 204;
Uint8 a= 0;
unsigned long tmp = (r << 24) + (g << 16) + (b << 8) + a;
printf("%lu\n", tmp );
}
|
The math is supposed to come out with 3422604288, whereas it prints out 18446744072837188608 instead. I'm just wondering what an equivalent operation would be, that is the same on 32 bit and 64 bit platforms.
Mod Edit: [syntax="lang" ][/syntax] is what you were looking for ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Zeroth
|
Posted: Fri May 01, 2009 8:43 pm Post subject: Re: 32bit to 64bit c code errors |
|
|
Nevermind, I found a fix. For reference, you have to prepend r,g,b, and a with (long), otherwise, it doesn't shift properly. |
|
|
|
|
![](images/spacer.gif) |
|
|