Date: Wed, 11 Mar 1998 12:54:23 +0100 (MET) From: Hans-Bernhard Broeker To: Eli Zaretskii cc: djgpp workers list Subject: Re: errno constants in In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 11 Mar 1998, Eli Zaretskii wrote: > On Wed, 11 Mar 1998, Hans-Bernhard Broeker wrote: > > In other words: it's always an lvalue, but not necessarily a simple > > variable. > > > The scheme I saw suggested was to do: > > > > > > errno = 0; /* or EOK */ > > > y = sqrt(x); > > > if (errno == EDOM) ... > > > > This scheme happens to be explained in the following footnote in the > > Standard, yes. But then, there *have* to be better ways of handling such > > conditions. > Even though errno is an lvalue, it still makes sense to not assign > anything BUT ZERO to it. 100% correct (for an application program, that is: the libc sources have a different game to play, of course :-) And a further note: all libc functions not *defined* by the Standard to do something specific with errno are explicitly allowed to trash it to their heart's content. I.e., once you call any function that's not documented to use errno to describe error conditions, you can't rely on errno preserving its value any more! One more quote from (ANSI C standardization commitee member) Plauger on the issue may be enlightening: ----------- If I had to identify one part of the C Standard that is uniformly disliked, I would not have to look far. Nobody likes errno or the machinery that it implies. [...] [...] We gave errno its own standard header mainly to ghettoize it. ----------- > For example, if we have > > #define errno (*get_errno_value()) > > then "errno = 0;" is OK, but "errno = EACCES;" is *not*. Right again. Although you're allowed to do 'errno = EACCESS', it is of no use at all: call any function like, say, isalpha(), that isn't documented to flag errors via errno, and your carefully set value may well be *garbage*. Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.