https://github.com/not-nik/libcx
cx is another attempt to bring exceptions to C
https://github.com/not-nik/libcx
c exception-handling exceptions signal-handler
Last synced: over 1 year ago
JSON representation
cx is another attempt to bring exceptions to C
- Host: GitHub
- URL: https://github.com/not-nik/libcx
- Owner: Not-Nik
- License: mit
- Created: 2020-09-27T12:19:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-27T12:22:25.000Z (almost 6 years ago)
- Last Synced: 2025-03-18T05:08:57.107Z (over 1 year ago)
- Topics: c, exception-handling, exceptions, signal-handler
- Language: C
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
This repo contains two similar versions of the same library.
cx is another attempt to bring exceptions to C.
# Comparing
|aspect|cx | cx2 |
|------|---|-----|
|Required standard library functions|`puts`, `printf`|`puts`, `printf`, `setjmp`, `longjmp`|
|Special return type|Yes|No|
|Thread safe|Somewhat|Definitely no|
|Custom errors|Yes|Yes|
|User defined error handler|Yes|Yes|
|Trace back after exception|Yes|Yes|
|Signal handling|No|Yes|
|TRY/FIN signature|(\) -> value of struct|(\) -> no return|
# cx
Lightweight version of cx.
### Minimal example
```c
#include
#include
void exception_handler(int err) {
puts("Error");
}
int_ex error_function() {
ERR(int_ex, 0);
OK(int_ex, 2) // Not executed
}
int main() {
set_handle(exception_handler);
int i = FIN(error_function())
}
```
# cx2
Fancy-pants version of cx.
### Minimal example
```c
#include
#include
void exception_handler(int err) {
puts("Error");
}
int error_function() {
ERR(0);
return 2; // Not executed
}
int main() {
set_handle(exception_handler);
FIN(int i = error_function())
}
```