Comment by K0nserv

2 days ago

I don't think I've ever seen a C function that uses unions for this purpose though?

I can think of two common patterns that I've seen frequently:

* Return NULL for errors (sometimes with a global errorno() function).

* Return an integer error with any return values as out parameters.

So if it is possible to improve, why doesn't anyone do it?

Because usually NULL is good enough and you need to have domain use case to make library for it.

> * Return an integer error with any return values as out parameters.

You must first standarize all that (usually negative) integers, make docs, check for it, do not make mistakes in your if's or case's...

And errno is just that - integers with a meaning. errno is even thread local now and quite safe to use but people on internet scream loudly when someone try to use that not app global varible :) I guess their llms statistically have less new texts feeded in ;)

At some point it is just better to return pointer to struct with all info you can imagine.

And how you think other languages implemented their Error type returns ? Just a struct or union with tag. Because current CPU's operate on simple type registers there is no other sane way to do it.