The c++ shell didn't give a error |
The point of C++-style casts is that it's harder to ignore the type system with them, because they're very restrictive.
The C-style cast tries very hard to perform the conversion, even when that conversion would throw away data. Specifically, C-style casts relax the rules on the C++ casts and then apply them repeatedly until a valid conversion path is found. This usually works even when such conversions don't make any sense.
The problem is that the size of
T*
,
int
, and
long
are not necessarily the same size, and that narrowing conversions between them are likely to throw away information. Their actual size depends on the implementation's data model. My computer is one such example where they differ; both
long and
T* are 8 bytes, but int is 4 bytes.
intptr_t
is an integer the same size as a plain pointer type, if it exists, but again converting it to
int
is likely to throw away information.
These functions should return a int |
Then I imagine you're about as close as you're going to get.
Are you sure they can't be construed to return an
intptr_t
?
Do these objects belong to a single array, where an int (or
std::ptrdiff_t
) could be used to indicate their offset?