问题
On my system errno defined as:
int * __error(void);
#define errno (* __error())
I understand errno is a macro and expands to * __error() function:
I searched everywhere (source on my system) but I can't find the definition of the
__error()function, can someone show/explain what would/should be the definition of it?How the expression
errno = 0works with the above definition (Assigning0to a function?)? Doeserrno = 0expands to* __error() = 0?
Thanks
回答1:
The __error function returns a pointer to the errno variable for the calling thread. The errno macro dereferences that pointer, resulting in an lvalue that can appear on either side of an equals sign.
To answer your questions:
The function determines the correct address for the
errnovariable for that specific thread. Each thread gets its own.Yes, it becomes
(* __error()) = 0;which assigns0to that thread'serrnovariable.
来源:https://stackoverflow.com/questions/14048187/understanding-c-errno