3 ms·
> One interesting tidbit is that errno is sometimes not a global variable at all, but a macro for (*_Error()). Having to set a real data object immediately afte
by asveikau 8y ago
> One interesting tidbit is that errno is sometimes not a global variable at all, but a macro for (*_Error()). Having to set a real data object immediately after performing hardware floating point ops would break the FPU pipeline. Allowing the check to be deferred until requested with this _Error() function doesn’t break the pipeline.
The best reason I can think of to make errno a function rather than a global integer is due to threads. The function can handle thread local storage. With a simple declaration of "extern int errno;" all threads get the same errno and clobber each other.
Nowadays there are things like __thread or c++11 thread_local but those mechanisms didn't exist when I first saw this pattern.
- aaronmdjones 8y agoIndeed that is the reason. On my system, I have: #define errno (*__errno_location ())