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)
{ {
struct btConvertPointerSizeT
{
union union
{ {
T* ptr; T* ptr;
size_t integer; size_t integer;
}; };
};
btConvertPointerSizeT converter;
const size_t bit_mask = ~(alignment - 1); const size_t bit_mask = ~(alignment - 1);
ptr = unalignedPtr; converter.ptr = unalignedPtr;
integer += alignment-1; converter.integer += alignment-1;
integer &= bit_mask; converter.integer &= bit_mask;
return ptr; return converter.ptr;
} }
#endif //BT_SCALAR_H #endif //BT_SCALAR_H