Liste des Groupes | Revenir à cl c |
On 2025-01-09, David Brown <david.brown@hesbynett.no> wrote:My comment about "lying to the user" is not in regards to what the language allows as defined behaviour - it's about what a function declaration says to other programmers. The function :On 08/01/2025 17:48, Andrey Tarasevich wrote:If the pointer came from the allocator, as required, there is no lie.
>>>
It is perfectly safe. One can even argue that standard declaration if
`free` as `void free(void *)` is defective. It should have been `void
free(const void *)` from the very beginning.
It is common in simple heap implementations for the allocated block to
contain data about the block, such as allocation sizes and pointers to
other blocks, in memory just below the address returned by malloc.
free() then uses its parameter to access that data, and may change it.
So "void free(const void *);" would be lying to the user.
The object is writable, and so free may strip away the qualifier
and do whatever it wants, like cover the object with 0xFE bytes.
Les messages affichés proviennent d'usenet.