4 ms·
> As far as I know, only Rust, C++, and C give support at the type-checking level to denote which functions will modify the interior of their arguments. 1. C a
by masklinn 7y ago
> As far as I know, only Rust, C++, and C give support at the type-checking level to denote which functions will modify the interior of their arguments.
1. C and C++ allow casting away constness, which may or may not be UB depending how the parameter is defined
2. Swift also provides this ability to an extent: struct parameters have to be flagged `inout` to be mutable
I'm sure there are others.
- gdxhyrd 7y agoCasting away constness in C++ is something it is virtually never done, and has to be done very explicitly.
- masklinn 7y ago> https://github.com/search?q=const_cast&type=Code https://github.com/search?q=const_cast&type=Code We must have very different notions of "virtually never": https://github.com/search?q=const_cast&type=Code https://github.com/search?q=const_cast&type=Code > has to be done very explicitly. That doesn't make it visible to the caller.
- nwallin 7y agoRust can throw away constness in unsafe blocks, which carries the same caveat emptor that const_cast carries.
- steveklabnik 7y agoOnly in certain circumstances, though.