Sujet : Re: So You Think You Can Const?
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 13. Jan 2025, 03:26:33
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86jzaz78km.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Keith Thompson <Keith.S.Thompson+
u@gmail.com> writes:
All the standard really says about "const" is that directly modifying
a const-qualified object is a constraint violation, and indirectly
modifying it has undefined behavior. [...]
This description isn't exactly right. The constraint violation is
for trying to modify an object through an lvalue that is not
modifiable, whether or not the object being referenced is const
qualified. There is undefined behavior for trying to modify a const
object, but only for objects _defined_ with a const-qualified type.
So the rule doesn't apply to any object that resides in allocated
memory, because those objects are not named in any declaration, and
thus not defined with a const-qualified type.