Re:Making a Go program 70% faster with a one character change
by account42 on Tuesday November 15, 2022 @04:11AM
(#33606957)
No, the primary point of a const cast is "I need to pass this to an API that expects a non-const pointer even though it won't mutate it".
Casting const away and then mutating is a footgun as you are in undefined behavior territory as soon as your pointer/reference is not just const itself but points to a const variable.
Casting const away and then mutating is a footgun as you are in undefined behavior territory as soon as your pointer/reference is not just const itself but points to a const variable.