5 ms·
> You don't have to "roll your own" for the cases that are always defined. That means, when NULLs and 0 aren't involved, realloc works, call it from your "myrea
by cbsmith 11y ago
> You don't have to "roll your own" for the cases that are always defined. That means, when NULLs and 0 aren't involved, realloc works, call it from your "myrealloc" function. For 0 and NULL, make sure that your "myrealloc" function handles them exactly as you'd like.
Ah, I misunderstood what you meant by "doing it in your own function". Yes, wrapping the semantics will work, though doing it right and without imposing some overhead takes a bit of work.
> It's not how C traditionally worked. Almost every function was knowingly made to be not "too good." I see modern programmers expect something else, what even 100 times slower languages not always give. Special cases have different possible treatments, and as soon as the exist nobody can make something that would please everyone.
As the original post pointed out, traditionally it didn't work like this. This is how it has evolved.
I did use poor semantics though, as "undefined behaviour" has a specific meaning in C that is of course how the language was defined. What I meant was "ambiguous or unwanted behaviour". Having a clear behaviour for a particular case, even if it is just returning an error code, is fine by me.