Considering the following code (and the fact that VirtualAlloc()
returns a void*
):
BYTE* pbNext = reinterpret_cast<BYTE*>(
VirtualAlloc(NULL, cbAlloc, MEM_COMMIT, PAGE_READWRITE));
why is reinterpret_cast
chosen instead of static_cast
?
I used to think that reinterpret_cast
is OK for e.g. casting pointers to and from integer types (like e.g. DWORD_PTR
), but to cast from a void*
to a BYTE*
, isn't static_cast
OK?
Are there any (subtle?) differences in this particular case, or are they just both valid pointer casts?
Does the C++ standard have a preference for this case, suggesting a way instead of the other?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…