4 ms·
Except gotos are legitimately useful for cleanup inside a function before you return an error (see: the Linux kernel). Exceptions have overhead, and you have no
by cyphar 10y ago
Except gotos are legitimately useful for cleanup inside a function before you return an error (see: the Linux kernel). Exceptions have overhead, and you have no idea where it will end up because the exception will bubble up the current call-stack, while gotos are local to the current function (and while longjmp is a mess, it is useful if you use clone(2)).
- adamnemecek 10y agoI'm well aware. I was talking about old school gotos, I should have probably said that.
- vvanders 10y agoYou should be using RAII for any resources that you need to automatically clean up, then any return statement will catch it. No need for exceptions.
- cyphar 10y agoRAII is not a feature of C. I was commenting on how gotos are not like exceptions, because gotos are actually useful and don't cause your program to make less sense as a result.