Re:Making a Go program 70% faster with a one character change
by morelisp on Monday November 14, 2022 @04:04PM
(#33601023)
Normally (when containers are not involved) this is exactly the point of a const cast.
[ Parent
| on HN ]
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.