On Jun 3, 2011, at 6:02 PM, koko wrote: ISO C++ forbids comparison between pointer and integer
on this code:
if (m_handle != INVALID_HANDLE_VALUE)
Is there a flag to set so this will be accepted?
Cast them both to a sufficiently wide common type. Something like:
if (reinterpret_cast<std::ptrdiff_t> (m_handle) != INVALID_HANDLE_VALUE)
std::ptrdiff_t is wide enough to hold the difference between pointers of the same type, and so is probably wide enough to hold any pointer. I assume that INVALID_HANDLE_VALUE is already of an integer type.
I use reinterpret_case<std::ptrdiff_t>() instead of just (std::ptrdiff_t)(), because this kind of conversion is skanky enough that it really should stick out in the source like a sore thumb. Besides, reinterpret_cast is really what you want, and the generic C-compatible one-size-fits-all type cast doesn't guarantee which flavor of type casting it will use in any particular situation.
At the risk of hiding the skankiness again, you could make it a define:
#define IS_INVALID_HANDLE_VALUE(h) (reinterpret_case<std::ptrdiff_t>(h) == INVALID_HANDLE_VALUE) |