3 ms·
Old school C hacker here. Can someone explain to me like I'm five how this is different from assert(p != NULL); // unrecoverable error if (p == NULL) {
by luckydude 13y ago
Old school C hacker here. Can someone explain to me like I'm five how this is different from
assert(p != NULL); // unrecoverable error
if (p == NULL) {
// no buffer for you but we'll continue
perror("malloc");
return (0);
}
- scott_s 13y agoYes, see my top-level comment in this thread. The key notion is that such errors are unrecoverable in a component, but you can recover from outside that component. So, if you are in component A, and you make a call to component B, and B has an unrecoverable error, B dies, but A can still recover. Without code, though, it's hard to see how this will actually work.
- luckydude 13y agoSeems like if you used processes to implement components and had a master process to respawn when a "component" dies then it is just assert() vs perror(). That's hand waving past any shared state but if you need that I suppose you use threads (I'm not a thread fan but I have to believe there is a thread_assert() that kills just that thread).
- asveikau 13y agoIntroducing threads and multiple processes seems slightly crazy. Remember that ideally the most common case is no failure at all and you don't want to introduce cost for that. Why not just have the point of failure unwind the stack until it sees a component boundary? Without multiple address spaces certain types of failure would blow up the whole process but that's life.
- mcguire 13y agoThat's how Erlang OTP does it, IIUC.