Monday, 9 September 2013

C++-style cast pointer to integer

C++-style cast pointer to integer

In the documentation for GetQueuedCompletionStatus(), MSDN says
This is done by specifying a valid event handle for the hEvent member of
the OVERLAPPED structure, and setting its low-order bit.
How do I do this with a C++-style cast, given that the event is of type
HANDLE, a typedef of void *? I can't directly apply |= 1 to the pointer,
reinterpret_cast converts between types with the same level of indirection
only, and static_cast also doesn't work. What's the C++ way of doing this,
avoiding C-style casts and using C++-style ones to convert to size_t? I
know the alternative is to use a union but that seems even more of a hack
than using C-style casts.

No comments:

Post a Comment