Error compiling in 64-bit linux

noisy
Posts: 10
Joined: Thu May 24, 2007 7:57 pm

Error compiling in 64-bit linux

Post by noisy »

Hi,

I get this error when compiling bullet in 64-bit linux:

Code: Select all

C++ ./out/linux/optimize/src/BulletCollision/CollisionShapes/btOptimizedBvh.o
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp: In member function ‘bool btOptimizedBvh::serialize(void*, unsigned int, bool)’:
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:922: error: cast from ‘void*’ to ‘unsigned int’ loses precision
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:962: error: cast from ‘unsigned char*’ to ‘unsigned int’ loses precision
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:1037: error: cast from ‘unsigned char*’ to ‘unsigned int’ loses precision
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp: In static member function ‘static btOptimizedBvh* btOptimizedBvh::deSerializeInPlace(void*, unsigned int, bool)’:
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:1084: error: cast from ‘void*’ to ‘unsigned int’ loses precision
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:1103: warning: comparison between signed and unsigned integer expressions
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:1105: warning: comparison between signed and unsigned integer expressions
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:1113: error: cast from ‘unsigned char*’ to ‘unsigned int’ loses precision
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp:1162: error: cast from ‘unsigned char*’ to ‘unsigned int’ loses precision
Cheers,
noisy
User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

Re: Error compiling in 64-bit linux

Post by Dragonlord »

What compiler are you using? Casts with precision loss should not yield errors only warnings although they are still incorrect, that's true.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Error compiling in 64-bit linux

Post by Erwin Coumans »

This contribution for serialization tries to align the memory to 16 bytes. For this alignment, we don't need full precision of the pointer, we only need the lower 4 bits. So in this case, the cast is safe.

You could replace the (unsigned) by (uintptr_t), but this breaks support on some platforms/compiler. I'll check to see if there is a better way to get rid of this problem. We basically only need to count the bytes from the start of the buffer, instead of using the full buffer address.

If you don't need serialization (saving/loading the BVH data to/from disk) you can just comment it out for now.

Thanks,
Erwin
noisy
Posts: 10
Joined: Thu May 24, 2007 7:57 pm

Re: Error compiling in 64-bit linux

Post by noisy »

thank you for the fast answers. I'll comment it out for now.
@Dragonlord: I'm using gcc-Version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

Re: Error compiling in 64-bit linux

Post by Dragonlord »

Proper solution would be to make a macro taking care of platform specific alignment requirements. Less hacky and safer ( if you consider macros safe that is :( )