Mail Archives: djgpp-workers/1998/03/10/20:42:29
At 01:10 3/10/1998 +0200, Eli Zaretskii wrote:
>> BTW, does anyone whether know whether assigning to errno by a user
>> program is portable behaviour? From what I have read, errno could even
>> be the result of a function call (i.e. an r-value)
>
>Yes, errno doesn't have to be an lvalue. A case in point is a
>multi-threaded environment, where you'd like each thread to have its own
>errno.
*Really?* But I believe there are cases where there's no other option. This
is from memory, but imagine a case where you are using `sqrt', and there are
no exceptions for math errors. Also, `errno' might already have been EDOM.
The scheme I saw suggested was to do:
errno = 0; /* or EOK */
y = sqrt(x);
if (errno == EDOM) ...
I see your point about multi-threading, but that needn't exclude `errno'
being an lvalue. For instance, the GNU libc implements it like this:
extern int *__errno_location();
#define errno (*__errno_location())
Then the `__errno_location' function takes care of acquiring the lock or
whatever, then returns `errno's address.
Does the ANSI standard really say `errno' need not be an lvalue??
Nate Eldredge
eldredge AT ap DOT net
- Raw text -