Rendered at 19:53:40 GMT+0000 (Coordinated Universal Time) with Cloudflare Workers.
hgs3 22 minutes ago [-]
> I really love Rust's error handling. Result forces you to address errors ...
> C's error handling story, in comparison, is straight up tragic. It seems to boil down to functions returning a "magic integer" like -1 or a null pointer to signal there was an error.
In C23 you can add the [[nodiscard]] attribute to the declaration of an enum or struct type, then at every call site of every function that returns said type, the C compiler will emit a warning if the result is unused. Instruct the compiler to treat warnings as errors and you can't ignore them.
Interestingly, Zig's error handling is conceptually C like, but limited to integer-like enums (no structs). It's basically a union of error integer code and success result. However, despite being limited to integers, Zig has dedicated compiler machinery for this so there's idiomatic consistency in Zig error handling.
I hope it can be useful for writing C ABI bindings especially for things like CLAP audio plugins. Writing C ABI plugins in Rust is needlessly painful. Crystal has a much easier way to write C bindings.
mizmar 1 days ago [-]
That linked stackoverflow post about dereference operators is really interesting. I guess it answers my question why do most struct members in posix have a prefix abbreviating name of the containing struct.
> C's error handling story, in comparison, is straight up tragic. It seems to boil down to functions returning a "magic integer" like -1 or a null pointer to signal there was an error.
In C23 you can add the [[nodiscard]] attribute to the declaration of an enum or struct type, then at every call site of every function that returns said type, the C compiler will emit a warning if the result is unused. Instruct the compiler to treat warnings as errors and you can't ignore them.
Interestingly, Zig's error handling is conceptually C like, but limited to integer-like enums (no structs). It's basically a union of error integer code and success result. However, despite being limited to integers, Zig has dedicated compiler machinery for this so there's idiomatic consistency in Zig error handling.
I hope it can be useful for writing C ABI bindings especially for things like CLAP audio plugins. Writing C ABI plugins in Rust is needlessly painful. Crystal has a much easier way to write C bindings.