Subject: Re: setting errno
From: [email-masked] (Jesper Eskilson)

21 Jan 1999 07:46:49 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
To: <[email-masked]>

> From: DJ Delorie <[email-masked]>
> To: [email-masked]
> Subject: Re: setting errno
> Date:  den 20 januari 1999 01:01
> 
> Tim Taylor wrote:
> > 
> > I'm porting a program that sets errno if an operation fails.  However,
in
> > the B20.1 errno is a macro that dereferences the pointer returned by a
> > function #define errno (*__errno())
> > 
> > What is the proper way to set errno in cygwin?
> 
> The correct way is, always was, and always will be, like thus:
> 
> 	#include <errno.h>
> 
> 	errno = N;
> 
> The ANSI spec requires it to be so.

More specifically, the ANSI spec requires that errno be an lvalue,
precisely to allow it to expand to a function returning a dereferenced
pointer. And quite a lot of compilers (or rather, header files) define it
that way.

Unfortunately, it is not often clearly stated that this is the case (not
every C programmer reads the ANSI standard that carefully), leading to
serious confusion when someone tries to handle errno as if it was a
variable.

-------------------------------------------------
Jesper Eskilson 
mailto:[email-masked]
http://www.sics.se/~jojo

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".