Sujet : Re: So You Think You Can Const?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 10. Jan 2025, 20:08:03
Autres entêtes
Organisation : None to speak of
Message-ID : <87r05apjvw.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13)
Kaz Kylheku <
643-408-1753@kylheku.com> writes:
On 2025-01-10, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
On 01/09/25 12:12 AM, Julio Di Egidio wrote:
I do not understand that: `free` is changing the pointed data, so how
can `const void *` even be "correct"?
>
`free` is destroying the pointed data.
>
Every object in C object model has to be created (when its lifetime
begins) and has to be eventually destroyed (when its lifetime ends).
>
That is not so. Literals can be put into a ROM image.
>
Well, sure, that is created in a factory, and destroyed when recycled.
>
The point is that the data's lifetime can span over countless
invocations of the program; the program can never observe a time which
is outside of the lifetime of those objects.
Any object with static storage duration has a lifetime that extends over
the entire execution of the program, so the program can never see such
an object outside its lifetime regardless of how it's stored.
If an object happens to be stored in a ROM image that the program
accesses directly, then sure, those bits can survive across multiple
executions. But the C "lifetime" extends only across a single
execution.
Nothing in particular *has* to happen when an object reaches the end of
its lifetime.
So, destruction is not really a "modifying" operation. Destruction of an
>
Destruction by malloc is modifying in any system that recycles the
memory for another allocation.
A call to malloc or free can modify the bits that make up an object, but
they do so only before or after the object's C lifetime.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */