Liste des Groupes | Revenir à cl c |
On 01/09/25 6:18 AM, David Brown wrote:I appreciate your point of view. And certainly there is no way (without UB, or at least implementation-specific details) for the code that calls "free" to see that "free" has changed anything via the pointer parameter - thus to the calling code, it makes no difference if it is "void *" or "const void *".>No, it wouldn't be. A deallocated data no longer exists from the user's point of view. There's nothing to lie about.
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.
Even without that, since you are now giving away the memory for re-use by other code, it's reasonable to say that "free" might change the data pointed to. (And a security-paranoid "free" might zero out the memory before returning it to the heap for re-use.)Such internal implementation details are completely irrelevant to the matter at hand, which is purely conceptual in essence. The rest I've explained above.
Les messages affichés proviennent d'usenet.