meiyunyang / chipmunk-physics

Automatically exported from code.google.com/p/chipmunk-physics
MIT License
0 stars 0 forks source link

On 64-bits, CP_HASH_PAIR generates warnings. #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by felipe.l...@gmail.com on 18 Jul 2008 at 2:49

GoogleCodeExporter commented 8 years ago
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.

Original comment by diogo...@gmail.com on 5 Nov 2008 at 2:38

GoogleCodeExporter commented 8 years ago
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

Original comment by diogo...@gmail.com on 5 Nov 2008 at 3:05

GoogleCodeExporter commented 8 years ago
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!

Original comment by felipe.l...@gmail.com on 13 Jul 2009 at 3:12

GoogleCodeExporter commented 8 years ago
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.

Original comment by slemb...@gmail.com on 27 Aug 2009 at 12:47