cease is a simplistic C23 library for monadic error handling.
Refer to include/cease.h for documentation.
Can be installed with CMake using FetchContent.
First, specify its installation in CMakeLists.txt:
include(FetchContent)
FetchContent_Declare(
cease
GIT_REPOSITORY https://github.com/maxicot/cease.git
GIT_TAG main
)
FetchContent_MakeAvailable(cease)
Then it can be treated as a normal library in your CMakeLists. After you've linked it, you merely need to include it in your C code:
#include "cease.h"A simple usage example:
#include "cease.h"
// The return type is `int`
ResultMonad divide(int a, int b) {
if (b == 0) {
return result_error(EDOM);
}
int result = a / b;
return result_from_unallocated(&result, sizeof(result));
}
int main() {
result_unwrap(divide(1, 0)); // panics
}- Type-unsafety;
- Allocation overhead.
Not the most idiomatic way to handle errors in C, the language also not being particularly suitable for its implementation (at least one that would be any good). Advised against in production.