Added all remaining gists.

This commit is contained in:
Miguel Astor
2023-06-21 21:40:51 -04:00
parent 22ff5bfa25
commit b0ca706a25
26 changed files with 892 additions and 0 deletions

1
exceptions.h/README.md Normal file
View File

@@ -0,0 +1 @@
Some practice with setjmp and longjmp.

16
exceptions.h/exceptions.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
#include <setjmp.h>
static jmp_buf env;
typedef int exception_t;
exception_t excptno;
#define try if ((excptno = setjmp(env)) == 0)
#define catch else
#define throw(X) longjmp(env, X);
#endif

17
exceptions.h/main.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include "exceptions.h"
void f() {
throw(89);
printf("All good.\n");
}
int main(void) {
try {
f();
} catch {
printf("Caught %d!\n", excptno);
}
return 0;
}