Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>"(CREATESTRUCT*) lParam"</strong> form is called a c-style cast. When this is used the compiler would try all possible ways to convert the expression (lParam - here) to the type (CREATESTRUCT* - here).</p> <p>Let me explain all possible ways of casting,</p> <ol> <li>Casting from "const/volatile T" to T - in C++ a programmer picks this way using <strong>const_cast</strong></li> <li>Casting from "T" to "R" where T and R are related. E.g. like int/char, Car/Vehicle etc. - in C++ a programmer picks this way of casting using <strong>static_cast</strong>.</li> <li>Casting from "T" to "R" where T and R are related, along with runtime check. E.g. T = Vehicle and R = Car, conversion from T type object to R type object is valid statically but in reality (at runtime) compiler (through hidden code) has to check if the object being type-casted is indeed a Car or a derivative of Car. - in C++ a programmer picks this way of casting using <strong>dynamic_cast</strong>.</li> <li>Casting from "U" to "V" where U and V are unrelated. - in C++ a programmer picks this way of casting using <strong>reinterpret_cast</strong>.</li> </ol> <p>If a c-style cast is used in C++ by a programmer, he is telling the compiler to try all possible ways to convert/perceive an expression to/as a particular type.</p> <p>The only reason c-style cast is dangerous is because the real intention of the programmer is not properly conveyed to the compiler and fellow programmers who would be reading the code. Sometimes a programmer may only have meant a static_cast and not reinterpret_cast but using a c-style cast would cause an error at run-time which could have been caught at compile time. Because compiler error would occur if the programmer uses static_cast on unrelated types.</p> <p>And user defined cast operators affects some behaviors a bit more (esp. static_cast) but does not change the fundamentals.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload