Reply to post: Are you sure?

In Rust we trust: Shoring up Apache, ISRG ditches C, turns to wunderkind lang for new TLS crypto module

dajames

Are you sure?

Rust allows and even promotes implicit actions and conversions, whereas C++ has been discouraging this for years now (C++ style casts).

Rust doesn't even allow an integer variable to be assigned the value from a shorter integer variable -- an explicit cast is needed (even though the value can never be truncated or otherwise corrupted). Such an assignment is always benign, and is accepted without even a warning in C++ (as it is in C). I'm not aware of any case in which Rust allows a coercion implicitly that C++ wouldn't.

C++ discourages C-style casts because they lack clarity of intent. Casts that are meaningful can be expressed in C++ as static_cast, dynamic_cast, etc., which make the programmer's intention explicit.

The meaning of a C-style cast depends on its context in the program, and it may end up being treated as a reinterpret_cast, which is likely to result in non-portable or undefined behaviour. That's why they're discouraged.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon