by Gibbon1 · 7y ago · 0 comments
typedef struct
{
int err;
int value;
} rtn_t;
rtn_t rtn = foo();
if(rtn.err < 0)
printf( "err=%i", rtn.err);
else
printf( "value = %i\n", rtn.value);A seasoned dev that thinks errno and longjump are good idea's should have retired 25 years ago.
But only one of them would make sense at a given moment, so why waste memory?
By comparison some something like https://github.com/oktal/result will tell you if it's a success or error without any magic error codes that actually mean success.
You could do this with a type bit + union in C, it's just more painful without templates
In c it'll be either in a register or on the stack.