Aloush154 / bullet

Automatically exported from code.google.com/p/bullet
Other
0 stars 0 forks source link

Error when casting char* to long. #779

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In bDNA.cpp in Extras/Serialize/BulletFileLoader in bDNA::init, a cast from 
char* to long occurs.  I understand from posts on the forums that this isn't 
much of an issue because you are only interested in the first few bits and this 
only generates a warning on most systems.

On my system (MinGW64) this generates a compile error.  Changing the "long" to 
"intptr_t" resolves this issue.  I couldn't find any platforms that fail to 
define it and it is included from STL files already included in that same file. 
 So it really was just a matter of swapping out the types in 3 places.  Patch 
file follows(generated with TortoiseUDiff).

Original issue reported on code.google.com by makoener...@gmail.com on 5 Dec 2013 at 7:34

Attachments:

GoogleCodeExporter commented 8 years ago
In my opinion you should never cast a pointer to a long or int or anything 
other than another pointer type.  This has been the reason why so many programs 
don't work when moving from 32 to 64 bit for instance in the past.  When you do 
a cast from char* to long you are relying on an assumption which may not hold 
true between architectures.  Windows 64 uses the LLP64/IL32P64 data model which 
is why the compiler complains because a long is still 32 bit while a pointer is 
64 bit.

For the most part the forum posts are right, but I try to avoid this practice 
in general because it could come back a bite you later.

Original comment by akei...@gmail.com on 6 Dec 2013 at 12:14

GoogleCodeExporter commented 8 years ago
Some further testing of this change I made has shown at least on Linux with 
GCC, stdint.h has to be included to be able to use the "intptr_t" datatype.

Original comment by makoener...@gmail.com on 8 Dec 2013 at 5:02

GoogleCodeExporter commented 8 years ago

moved to https://github.com/bulletphysics/bullet3/issues/70

Original comment by erwin.coumans on 30 Mar 2014 at 5:22