Search notes:

libc: setjmp - longjmp

#include <stdio.h>
#include <setjmp.h>

jmp_buf env;

void func() {
    printf("func, calling longjmp\n");
 
    longjmp(env, 42);
 // longjmp does not return
    printf("func, after calling longjmp\n");
}

int main() {

    switch (setjmp(env)) {
 // setjmp returns twice, once with 0
 // and one with the value passed to longjmp
    case 0:
       printf("call func()\n");
       func();
       break;
    case 42:
       printf("setjmp evaluated to 42\n");
       break;
    default:
       printf("setjmp evaluated to neither 42 nor 0\n");
    }
}
When run, this program prints
call func()
func, calling longjmp
setjmp evaluated to 42

GCC built-in functions __builtin_setjmp and __builtin_setjmp

GCC provides the built-in functions __builtin_setjmp and __builtin_longjmp which are similar to, but not interchangeable with setjmp and longjmp.
The built-in versions are used internally by GCC's libraries to implement exception handling on some targets.
The standard C library functions (<setjmp.h>) are preferred in regular user code.

See also

The Standard C Library

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758201062, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/C/libc/functions/setjmp-longjmp(81): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78