orangeduck / tgc

A Tiny Garbage Collector for C
Other
968 stars 64 forks source link

Make free accept a const pointer #1

Closed Leandros closed 6 years ago

Leandros commented 8 years ago

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 accept const pointers: http://yarchive.net/comp/const.html

orangeduck commented 8 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.

orangeduck commented 6 years ago

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.