Apparently, I made a mistake in my initial section on the answer. They are roughly equivalent. Although compound type names such as long long or void * cannot directly use functional syntax (i.e. long long(val) does not work), using typedef can work around this problem.
Both excellent signs are very bad, they should be avoided. For example:
const char c = 'a'; void *fred = (void *)(&c);
It works, and it should not.
The initial C-style notation sometimes behaves like static_cast , sometimes like const_cast , sometimes like reinterpret_cast , or even a combination of the two depending on the particular situation in which it was used. These semantics are quite complex, and itβs not always easy to say exactly what happens in any situation.
I switched to using mostly C ++ style styles static_cast<type>(val) and never used C style casts. Based on my research on this, I am also going to stop using style functions for anything. The question " C ++ syntax syntax styles has an excellent answer (accepted) that details why.
Omnifarious Jan 23 '11 at 19:09 2011-01-23 19:09
source share