delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/03/10/20:42:29

Date: Tue, 10 Mar 1998 17:41:15 -0800 (PST)
Message-Id: <199803110141.RAA22234@adit.ap.net>
Mime-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>,
Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: errno constants in <errno.h>
Cc: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>,
djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019