Closed Leandros closed 6 years ago
The rationale of Linux makes sense for kfree
and free
. But tgc_free
is a bit different as it can call a destructor on the pointer it frees, which may modify the memory it points to.
Let me have a think - and also I need to consider a bit more the whole destructor feature as there are a number of ways the behaviour may be a little unexpected compared to something like C++ or Java.
In the end I'm not going to do this because tgc_free
actually calls the destructor before the memory is free'd so it isn't a const
operation.
Don't repeat the mistakes the standard library did, make free accept a
const
pointer, that the caller never has to cast their pointers.Rationale by Linus Torvalds why free (or in his case
kfree
) should acceptconst
pointers: http://yarchive.net/comp/const.html