Skip to content
/ libcx Public

cx is another attempt to bring exceptions to C

License

Notifications You must be signed in to change notification settings

Not-Nik/libcx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 (<struct with .ex and .val>) -> value of struct (<any code block>) -> no return

cx

Lightweight version of cx.

Minimal example

#include <cx.h>
#include <stdio.h>

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

#include <cx2.h>
#include <stdio.h>

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())
}

About

cx is another attempt to bring exceptions to C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published