C-style casting

suggest change

C-Style casting can be considered ‘Best effort’ casting and is named so as it is the only cast which could be used in C. The syntax for this cast is (NewType)variable.

A C-style cast performs the first of these conversions that is valid:

It can also cast to an inaccessible base and cast away const as part of those combinations. The bullets above are not function-call syntax you can copy with NewType filled in.

Functional notation, NewType(expression), is similar, but the type name has to be a single word (or a typedef). A type such as unsigned int does not fit that syntax.

Prefer a C++ cast. It is easier to see, and each form accepts fewer conversions, so an unintended reinterpret_cast is not chosen silently. An invalid cast is still diagnosed at compile time.

As this cast can result in unintended reinterpret_cast, it is often considered dangerous.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents