Sujet : Re: So You Think You Can Const?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 12. Jan 2025, 03:29:09
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250111182556.466@kylheku.com>
References : 1 2 3 4 5 6
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-01-11, Andrey Tarasevich <
andreytarasevich@hotmail.com> wrote:
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.
Most constness about C is about creating a read-only alias designating
an object. It's integrated in the type system in a way that encourages
spreading/contagion.
However, objects defined with a declared type that is const are allowed
to be actually read-only.
In C and C++ (as well in virtually all higher level languages)
"constness" is not a physical concept.
It is for defined objects. A const object of static duration can be
put into ROM, or virtual memory configured read-only. Either of these
can generate a trap if written.
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.
Often it is, but not always.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca