Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [setjmp]

Anything related to the setjmp() and longjmp() routines in the C standard library (provided by the setjmp.h header file), which provide control flow that modify the usual call and return sequence of a subroutine.

setjmp
3 votes
1 answer
127 views

Primes using setjmp

I wrote a simple Haskell function, that gives a list of primes. primes' :: [Int] -> [Int] primes' (p : xs) = p : primes' (filter (\x -> x `rem` p /= 0) xs) primes :: [Int] primes = primes' [2 .....
Andrey's user avatar
  • 71
0 votes
2 answers
103 views

using setjmp/longjmp to time-slice tasks using a timer on ESP32S3 bare-metal

I have implemented in C a round-robin scheduler that cycles through 3 tasks. I want to time-slice my tasks, meaning that when a task takes more than a pre-determined timeout value x, it is interrupted ...
UserBoy's user avatar
2 votes
1 answer
59 views

exception handler with siglongjmp interrupting I/O

While working on the homework problem 8.25 in CSAPP, I referred to its solution available at https://dreamanddead.github.io/CSAPP-3e-Solutions/. The provided solution includes the following C code: #...
sridoo's user avatar
  • 43
4 votes
1 answer
172 views

setjmp/longjmp in C++: Is this undefined behaviour?

Does the following code invoke undefined behaviour: #include <iostream> #include <csetjmp> jmp_buf buffer1; jmp_buf buffer2; class Test { public: ~Test() { ...
dohashi's user avatar
  • 1,831
1 vote
1 answer
175 views

How to free the call stack in C?

I have created a calculator using RDP (recursive descent parser) to parse and evaluate mathematical expressions "such as: 5cos(30) -5(3+5)". The thing is I also have tried to include ...
Achraf's user avatar
  • 19
3 votes
2 answers
138 views

Implement setjmp and longjmp functionality with ucontext

I am trying to grasp some key concepts in order to fully understand the ucontext and setjmp libraries. On what concerns ucontext: User context, eg program counter and stack register. Is saved on a ...
kostas's user avatar
  • 51
1 vote
0 answers
66 views

Common Lisp CFFI setjmp/longjmp

I am calling functions in the MuPDF C library using Common Lisp and CFFI. MuPDF uses setjmp/longjmp for exception handling. The MuPDF website states: All functions you call should be guarded by a ...
buggyCoder's user avatar
1 vote
1 answer
98 views

How to know if my signal handler is interrupting an async-signal-unsafe function?

According to this answer, I can only longjmp() out of a signal handler if it is not calling an async-signal-unsafe function. Is there a reliable way to know, from inside the signal handler, if the ...
lvella's user avatar
  • 13.2k
1 vote
0 answers
33 views

Why can't I use value = = setjmp(env); [duplicate]

Recently while reading csapp, I find in nonlocal jump, I can't use int value; value = setjmp(env); but I can use this if(setjmp(env)){ // code } Why? int value; value = setjmp(env);
Musicminion's user avatar
4 votes
1 answer
825 views

How do I ensure the `SIGINT` signal handler is called as many times as `Ctrl+C` is pressed (with `longjmp`)?

Setup In the code below, which simply prints some text until it times out, I added a handler (onintr()) for SIGINT. The handler onintr() does the following: Resets itself as the default handler. ...
gomfy's user avatar
  • 704
2 votes
1 answer
82 views

Using the setjmp and longjmp

Having such a simple C code #include <stdio.h> #include <setjmp.h> void Com_Error(int); jmp_buf abortframe; int main() { if (setjmp (abortframe)){ printf("...
 darro911's user avatar
3 votes
3 answers
822 views

Special treatment of setjmp/longjmp by compilers

In Why volatile works for setjmp/longjmp, user greggo comments: Actually modern C compilers do need to know that setjmp is a special case, since there are, in general, optimizations where the change ...
Petr Skocik's user avatar
  • 59.6k
1 vote
2 answers
143 views

Does setjmp literally save the state of the program?

So, if I were to malloc 500 bytes, then use setjmp to save the state, then free the 500 bytes, then longjmp, would I be able to access those 500 bytes? For example: #include <stdio.h> #include &...
dfmaaa1's user avatar
  • 77
4 votes
4 answers
915 views

Using setjmp and longjmp with a local jmp_buf

In the case that a local jmp_buf is actually represented by registers rather than stack memory, is it possible for setjmp or longjmp to cause the contents of the local jmp_buf to be indeterminate when ...
jxh's user avatar
  • 70k
0 votes
1 answer
156 views

setjmp / longjmp does not jump where I think it should

I would like to understand how setjmp / longjmp works, so I created an example program, where routineA prints even, routineB prints odd numbers and they jump to each other with longjmp: #include <...
z32a7ul's user avatar
  • 3,727

15 30 50 per page
1
2 3 4 5
13