delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/03/11/06:56:34

Date: Wed, 11 Mar 1998 12:54:23 +0100 (MET)
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
cc: djgpp workers list <djgpp-workers AT delorie DOT com>
Subject: Re: errno constants in <errno.h>
In-Reply-To: <Pine.SUN.3.91.980311133416.7959G-100000@is>
Message-ID: <Pine.LNX.3.93.980311123903.27664H-100000@acp3bf>
MIME-Version: 1.0

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.

- Raw text -


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