4 ms·
Not to mention that you also lose the error context. That boolean "is_valid" flag is not really informative of what happened. For example, if the image to load
by amadvance 5y ago
Not to mention that you also lose the error context. That boolean "is_valid" flag is not really informative of what happened.
For example, if the image to load doesn't exist, you may want to print/log such path.
The goto looks like a better approach.
- flohofwoe 5y agoYou can just as well use a nested common error struct which has more detailed error information instead of just an "is_valid" bool, and also turn the whole return value into a tagged union to save some space (so the return value either contains a success value, or error data, but not both). You just don't have the high-level syntax sugar to create or deal with tagged unions in C.