I have any array of type int and need to store, within this array, a pointer to another part of the array.
The problem is that, on 64bit systems, the size of the pointer is 8 bytes, and the size of the int is 4 bytes causing complier warnings (e.g. warning cast to pointer from integer of different size)
I (think0 i understand why the complier is moaning, obviously trying to fit 8 bytes into 4 bytes isn't a clever idea. The problem is the array is supplied to me as is and I must use only the array for storage.
If you are referring to the same array, why don't you store just the index?
#include <limits>
#include <boost/static_assert.hpp>
int array[ARRAY_DIMENSION];
/**
* the following line will cause an error at compile-time if size_t
* is not enough to index the array.
*/
BOOST_STATIC_ASSERT(std::numeric_limits<size_t>::max() >= ARRAY_DIMENSION);
int access_array(size_t index)
{
size_t intended_index = array[index];
return array[intended_index];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With