3 ms·
The static_cast vs. reinterpret_cast is also executable documentation for your readers. Sounds like you have a strong handle on this, and it's a free opportuni
by ycombobreaker 6y ago
The static_cast vs. reinterpret_cast is also executable documentation for your readers. Sounds like you have a strong handle on this, and it's a free opportunity to make your future maintainers' lives a little bit easier.
- gok 6y agoI appreciate that in general but not here. What does reinterpret_cast<intptr_t>(p) tell a reader that (intptr_t)p doesn't?
- ycombobreaker 6y agoSince this is about maintenance, it's ultimately craftsmanship (IMHO) amd I don't think I can give a great answer without knowing real context. Here's one possibility that comes to mind: Places where I would _expect_ to see something like this are C APIs where void pointers are used to provide "userdata context", such as pthread_create. Using the reinterpret-cast-to-pointer-sized-thingie(void* or intptr_t or uintptr_t) makes it clear that we're discarding all type safety and probably doing something similar. The C style cast does not express that as clearly. Is the impact substantial? Not really. But in maintenance of long lived code bases, small impacts accumulate.