Liste des Groupes | Revenir à cl c |
On 01/10/25 10:37 AM, Kaz Kylheku wrote:
>Destruction by malloc is modifying in any system that recycles the>
memory for another allocation.
From such a radically "physical" point of view, nothing is and nothing
will ever be `const`... Sorry, this is not even close to what
"constness" in C is about.
>
In C and C++ (as well in virtually all higher level languages)
"constness" is not a physical concept. It is a purely high-level
logic-level concept, designed, implemented and enforced entirely by
the author of the code (of the public interface of the module) in
accordance with their intent.
>
It has absolutely no relation to any physical modifications that might
occur anywhere in the execution environment. Nobody cares whether
something somewhere gets "modified". It is always a question of
whether _I_ want to recognize such modifications as part of the public
interface designed by me. I'm the one who says whether the operation
is "constant" or not, based purely on my idea of "logical constness".
>
That's the reason `const` exists in C (and C++).
>
However (returning to the more narrowly focused matter at hand), two
things - creation and deletion of objects - will always indisputably
stand apart as operations that transcend/defeat/ignore the idea of
"constness" with relation to the object itself. Creation/deletion
might logically be seen as "non-constant" wrt to the surrounding
environment (e.g. memory manager), but wrt to the object itself they
shall not (and, obviously, cannot) care about its "constness" at all.
>
An object begins being `const` only after the process of its creation
(construction) is complete. [...]
Les messages affichés proviennent d'usenet.