longjmp

What sense do these clobbered variable warnings make?

十年热恋 提交于 2019-12-03 11:21:44
问题 I have a function like this: #include <setjmp.h> jmp_buf buf; void func2(int g); extern int some_global; void func(int x) { if (setjmp(buf)) return; if (some_global) x += 5; func2(x); } GCC (gcc (Debian 4.4.5-8) 4.4.5) gives a warning: test.c: In function ‘func’: test.c:5: warning: argument ‘x’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] Why???? I mean, obviously I don't care if x is clobbered or not, because it can't possibly be used after setjmp returns. Even the compiler

What sense do these clobbered variable warnings make?

廉价感情. 提交于 2019-12-03 01:49:27
I have a function like this: #include <setjmp.h> jmp_buf buf; void func2(int g); extern int some_global; void func(int x) { if (setjmp(buf)) return; if (some_global) x += 5; func2(x); } GCC (gcc (Debian 4.4.5-8) 4.4.5) gives a warning: test.c: In function ‘func’: test.c:5: warning: argument ‘x’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] Why???? I mean, obviously I don't care if x is clobbered or not, because it can't possibly be used after setjmp returns. Even the compiler should be aware of something so blindingly obvious, given that it has some kind of special knowledge of

excellent setjmp/longjmp tutorials [closed]

点点圈 提交于 2019-11-30 09:37:27
Hi I'd like to read good tutorials on setjmp/longjmp in C. It'd be better if there're examples which are real rather than artificial. Thanks. It's not really a tutorial as such, but the libpng documentation describes how the library uses setjmp/longjmp to do error handling. Eli Bendersky The book "C interfaces and implementation" explains the concept well and implements a usable "exception" simulation in C using these constructs. The code for it (chapter 4) is freely available online here . Edit: also see this SO thread Then you should read Advanced Programming in the UNIX(R) Environment (2nd

Multitasking using setjmp, longjmp

白昼怎懂夜的黑 提交于 2019-11-30 06:23:27
问题 is there a way to implement multitasking using setjmp and longjmp functions 回答1: You can indeed. There are a couple of ways to accomplish it. The difficult part is initially getting the jmpbufs which point to other stacks. Longjmp is only defined for jmpbuf arguments which were created by setjmp, so there's no way to do this without either using assembly or exploiting undefined behavior. User level threads are inherently not portable, so portability isn't a strong argument for not doing it

What are some “good” ways to use longjmp/setjmp for C error handling?

混江龙づ霸主 提交于 2019-11-30 01:46:58
I have to use C for one project and I am thinking of using longjmp/setjmp for error handling as I think it will be much easier to handle error in one central place than return codes. I would appreciate if there are some leads on how to do this. I am particularly concerned with resource cleanup being correctly done if any such error occurs. Also how do I handle errors that result in multi-threaded programs using them? Even better, is there some C library that already exists for error/exception handling? Have a look at this example/tutorial: http://www.di.unipi.it/~nids/docs/longjump_try_trow

excellent setjmp/longjmp tutorials [closed]

旧街凉风 提交于 2019-11-29 15:03:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Hi I'd like to read good tutorials on setjmp/longjmp in C. It'd be better if there're examples which are real rather than artificial. Thanks. 回答1: It's not really a tutorial as such, but the libpng documentation describes how the library uses setjmp/longjmp to do error handling. 回答2: The book "C interfaces and

What are some “good” ways to use longjmp/setjmp for C error handling?

吃可爱长大的小学妹 提交于 2019-11-28 21:17:57
问题 I have to use C for one project and I am thinking of using longjmp/setjmp for error handling as I think it will be much easier to handle error in one central place than return codes. I would appreciate if there are some leads on how to do this. I am particularly concerned with resource cleanup being correctly done if any such error occurs. Also how do I handle errors that result in multi-threaded programs using them? Even better, is there some C library that already exists for error/exception

OCaml internals: Exceptions

点点圈 提交于 2019-11-28 18:46:17
I'm curious to know how exceptions are dealt with in OCaml runtime to make them so lightweight. Do they use setjmp/longjmp or do they return a special value in each function, and propagate it? It seems to me that longjmp would put a little strain on the system, but only when an exception is raised, while checking for each function return value would need to check for every and each value after calling a function, which seems to me would put a lot of checks and jumps, and it seems it would perform worst. By looking at how OCaml interfaces with C ( http://caml.inria.fr/pub/docs/manual-ocaml

Multitasking using setjmp, longjmp

余生颓废 提交于 2019-11-28 17:57:47
is there a way to implement multitasking using setjmp and longjmp functions You can indeed. There are a couple of ways to accomplish it. The difficult part is initially getting the jmpbufs which point to other stacks. Longjmp is only defined for jmpbuf arguments which were created by setjmp, so there's no way to do this without either using assembly or exploiting undefined behavior. User level threads are inherently not portable, so portability isn't a strong argument for not doing it really. step 1 You need a place to store the contexts of different threads, so make a queue of jmpbuf

longjmp() from signal handler

↘锁芯ラ 提交于 2019-11-27 23:17:52
I'm using the following code to try to read an input from user and timeout and exit if more than 5 seconds pass. This is accomplished through a combination of setjmp/longjmp and the SIGALRM signal. Here's the code: #include <stdio.h> #include <setjmp.h> #include <unistd.h> #include <string.h> #include <sys/signal.h> jmp_buf buffer; // this will cause t_gets() to return -2 void timeout() { longjmp(buffer, 1); } int t_gets(char* s, int t) { char* ret; signal(SIGALRM, timeout); if (setjmp(buffer) != 0) return -2; // <--- timeout() will jump here alarm(t); // if fgets() does not return in t