3 ms·
It lacks 4th method that I find the best: with long jumps. I mean for example: jmp_buf errbuf; int result; if( !( result = set_jmp ) ) { /* Code
by krollew 14y ago
It lacks 4th method that I find the best: with long jumps. I mean for example:
jmp_buf errbuf;
int result;
if( !( result = set_jmp ) )
{
/* Code to do on fail. Result may be some error code */
}
else
{
someaction( par1, par2, ..., errbuf);
anotheraction( par1, par2, ..., errbuf);
/* Etc. */
}
errbuf might be global if you prefer, but I'd rather avoid them. When something is wrong called function calls longjmp(errbuf, errorcode).
- adestefan 14y agoA longjmp is just a fancy goto. If it's all local to the function, just use goto.
- krollew 14y agoThat's more than goto: 1. It can be called from any place in code. 2. Its call can be written in function. You don't write so much ifs whenever you call it.
- haberman 14y agoUnfortunately longjmp() is not available in the Linux kernel, so I integrated the BSD implementation of it into my library/kmodule for this purpose: https://github.com/haberman/upb/blob/master/bindings/linux/setjmp.S https://github.com/haberman/upb/blob/master/bindings/linux/s...