4 ms·
> Undefined behavior[2] Given that this particular undefined behavior usually causes crashes in practice, I expect the author is talking about casting away the
by comex 3y ago
> Undefined behavior[2]
Given that this particular undefined behavior usually causes crashes in practice, I expect the author is talking about casting away the const but not actually writing to the pointer. Which is legal.
- paulddraper 3y agoOr a common situation is mutable -> const -> mutable. And that is legal.
- thetic 3y agoThe legal cases in which he needs to cast away const could be avoided if the arguments to called functions were appropriately qualified.
- LegionMammal978 3y agoHe never said he needs to cast away const to do what he is attempting to do, he just said that he wants to cast away const to reduce clutter, even though the program would have the same semantics as if he kept the const.
- thetic 3y agoIf only there were a way to indicate the function argument isn't mutated. </s> My spidey senses tingle whenever I see const-ness cast away because it almost always means something is wrong. Either a function is missing a qualifier on an argument, or something very unsafe is happening. Why force callers to cast away const-ness in hopes that everything will be fine when you can just write the correct function signature.