workaround for a GCC 4.2 compiler bug and warning in pointer conversion,

fixes Issue 615, thanks to Daniel Sefton for the report
This commit is contained in:
erwin.coumans
2012-03-30 19:15:55 +00:00
parent 4b92fbaccf
commit 8453942546

View File

@@ -521,19 +521,27 @@ struct btTypedObject
}; };
///align a pointer to the provided alignment, upwards ///align a pointer to the provided alignment, upwards
template <typename T>T* btAlignPointer(T* unalignedPtr, size_t alignment) template <typename T>T* btAlignPointer(T* unalignedPtr, size_t alignment)
{ {
union
{ struct btConvertPointerSizeT
T* ptr; {
size_t integer; union
}; {
const size_t bit_mask = ~(alignment - 1); T* ptr;
ptr = unalignedPtr; size_t integer;
integer += alignment-1; };
integer &= bit_mask; };
return ptr; btConvertPointerSizeT converter;
const size_t bit_mask = ~(alignment - 1);
converter.ptr = unalignedPtr;
converter.integer += alignment-1;
converter.integer &= bit_mask;
return converter.ptr;
} }
#endif //BT_SCALAR_H #endif //BT_SCALAR_H