Deutsch   English   Français   Italiano  
<vlu6qh$miie$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: So You Think You Can Const?
Date: Sat, 11 Jan 2025 08:38:40 -0800
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <vlu6qh$miie$1@dont-email.me>
References: <vljvh3$27msl$1@dont-email.me> <vlma9m$2s5e5$1@dont-email.me>
 <vlo0cm$2dkpd$9@dont-email.me> <vlqd4j$3s4ai$1@dont-email.me>
 <20250110103252.718@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 11 Jan 2025 17:38:41 +0100 (CET)
Injection-Info: dont-email.me; posting-host="773756ccf1076aa87277426826aeda67";
	logging-data="739918"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/JvHd+4jPc1kUB3U2PHq+Y"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PpzChiqRcBm1gxiRLOMQRTq/sjY=
In-Reply-To: <20250110103252.718@kylheku.com>
Content-Language: en-US
Bytes: 3298

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. An object stops being `const` the moment the 
process of its destruction begins. That's how it works in C and C++. 
(Again, using C++ as an example, you all know that `const` objects are 
not seen as `const` inside their constructors and destructors.) In C we 
don't have constructors and destructors, but we still naturally follow 
the same ideas in hand-written code. It would've been nice to have 
`free` to play along with this.

-- 
Best regards,
Andrey