Export to GitHub

chipmunk-physics - issue #1

On 64-bits, CP_HASH_PAIR generates warnings.


Posted on Jul 18, 2008 by Grumpy Horse

What steps will reproduce the problem? 1. Compile on a x86-64 machine with -Wall.

What is the expected output? What do you see instead? Expected: no warnings Got: lots of "cast from pointer to integer of different size" wherever CP_HASH_PAIR

What version of the product are you using? On what operating system? Chipmunk 4.0.2 on Gentoo Linux amd64.

Please provide any additional information below. The problem is that CP_HASH_PAIR uses unsigned ints, which have 32 bits in a 64 bits machine (which, of course, has 64 bits pointers). This doesn't break anything, but generates a lot of warnings and may eventually create hash collisions, although I think that's highly improbable.

Comment #1

Posted on Nov 5, 2008 by Swift Ox

It would be nice to have this fixed. Even more for those whose project demand passing "-pedantic-errors" to the compiler. Then, the warning becomes an error.

Comment #2

Posted on Nov 5, 2008 by Swift Ox

Well, I did a HORRIBLE hack around it, but it passed by my compiler. Here it go (don't be scared!):

int INT_SIZE = sizeof(int);

if INT_SIZE == 4

define CP_HASH_PAIR(A, B) ((unsigned int)(A)*CP_HASH_COEF ^ (unsigned

int)(B)*CP_HASH_COEF)

else

define CP_HASH_PAIR(A, B) ((unsigned long int)(A)*CP_HASH_COEF ^ (unsigned long

int)(B)*CP_HASH_COEF)

endif

Comment #3

Posted on Jul 13, 2009 by Grumpy Horse

This seems to be fixed on the soon-to-be-released Chipmunk 5.0, but I can't close this bug by myself.

Thanks, slembcke!

Comment #4

Posted on Aug 27, 2009 by Happy Giraffe

I changed the type of Chipmunk hash values to size_t some time ago. I was told that this was the safest value across different compilers to consistently be native integer sized.

Status: Fixed

Labels:
Type-Defect Priority-Medium