3 ms·
The main issues with errno are you need to remember to reset it before you enter a context whose failability you care about, so any code which relies on errno m
by masklinn 4y ago
The main issues with errno are you need to remember to reset it before you enter a context whose failability you care about, so any code which relies on errno must be:
errno = 0
// code which may error here
if(errno) { … }
And that errno is notably not scoped, so the code which may error should only be composed of calls to libc, or code whose interaction with libc you understand perfectly, otherwise you need to save and restore errno around uncontrolled calls.
This is quite verbose, annoying, and error prone.
- lelanthran 4y ago> The main issues with errno are you need to remember to reset it before you enter a context whose failability you care about, so any code which relies on errno must be: > errno = 0 > // code which may error here > if(errno) { … } Which are the functions that set errno, and only errno, on failure? In practice, you will clear errno once, and then repeatedly check for failure after every call to a libc function. > And that errno is notably not scoped, so the code which may error should only be composed of calls to libc, or code whose interaction with libc you understand perfectly, otherwise you need to save and restore errno around uncontrolled calls. I don't understand what this means.