Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 32bit to 64bit c code errors
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Zeroth




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Zeroth




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: