i read in The Linux Programming Interface 29-2 Threads and errno the next :
On Linux, a thread-specific errno is achieved in a similar manner to most other UNIX implementations: errno is defined as a macro that expands into a function call returning a modifiable lvalue that is distinct for each thread.
and i wondered how can a function return a modifiable lvalue.
It is the macro that "returns" the modifiable lvalue, not the function call itself. The function returns a pointer and the macro dereferences this pointer. For example, errno.h
of the glibc source code defines the macro errno
like this:
# define errno (*__errno_location ())
This wording is a bit misleading:
errno
is defined as a macro that expands into a function call returning a modifiable lvalue that is distinct for each thread.
A more accurate wording would be:
errno
is defined as a macro that expands into an expression that contains a function call. This expression evaluates to a modifiable lvalue that is distinct for each thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With