Semantics always bother me; C++ style casting

K.I.L.E.R

Retarded moron
Veteran
Stupid question, however answering it will make me either feel better or swear a rainbow.

static_cast<TYPE>(someVal);

or

(TYPE)someVal;

Again, just semantics but I personally prefer the latter to the former because it's just less typing.
I'm inclined to believe the former to be the "correct" form, however I just really want to be wrong on this.
 
C++ style casting is the former and allows the compiler to catch a few possible errors it couldnt detect with C-Style casts (if used right of course). Besides they are ackward to type so you get a better feel how ugly casts are.

I guess you know theres reinterpret_cast, dynamic_cast and const_cast too?
(TYPE) is actually equivalent to reinterpret_cast<TYPE>.
 
c++ style is much more explicit about what it does, and also it might throw, which is a good thing to catch errors...
 
Sorry, that wasn't what I meant by type, yes reinterperet_cast is very useful when swapping endians.

Looks like I'm going to have to renege on ease of use for proper semantics. :(

Thanks.

C++ style casting is the former and allows the compiler to catch a few possible errors it couldnt detect with C-Style casts (if used right of course). Besides they are ackward to type so you get a better feel how ugly casts are.

I guess you know theres reinterpret_cast, dynamic_cast and const_cast too?
(TYPE) is actually equivalent to reinterpret_cast<TYPE>.
 
Back
Top