Or You Could Simplify The Error-Recovery Paths
Or You Could Simplify The Error-Recovery Paths
Posted Dec 29, 2014 23:11 UTC (Mon) by rleigh (guest, #14622)In reply to: Or You Could Simplify The Error-Recovery Paths by cesarb
Parent article: The "too small to fail" memory-allocation rule
This is certainly a partial solution for C. It's akin to a shared_ptr custom deleter. It's not really a great alternative to C++ destructors, because the cleanup still needs specifying by hand for each type instance and it's not really encapsulated as well since the cleanup function is either local to the translation unit or effectively public without additional measures, but it's probably the best you're going to get out of C. If you're going this far into the nonportable and nonstandard with C, I'd argue you'd be better off using standard and portable C++.