Re: declaring errno

From: Dave Thompson (david.thompson1_at_worldnet.att.net)
Date: 04/26/04


Date: Mon, 26 Apr 2004 03:07:23 GMT

On Wed, 21 Apr 2004 21:06:06 -0700, "Mac" <foo@bar.net> wrote:

> Is it legal to declare errno after you've included errno.h?
<snip>
> I see in the standard that errno may be a macro, and I see that defining
> errno is illegal, but I don't think the declaration above counts as a
> definition since it doesn't reserve storage. On the other hand, if errno
> IS a macro, the declaration above could easily be a syntax error after
> pre-processing.
>
7.1.3p1 list items 3 and 5:
Each macro name in any of the following subclauses (including the
future library
directions) is reserved for use as specified if any of its associated
headers is included;
unless explicitly stated otherwise (see 7.1.4).
Each identifier with file scope listed in any of the following
subclauses (including the
future library directions) is reserved for use as a macro name and as
an identifier with
file scope in the same name space if any of its associated headers is
included.

errno is either a macro or an identifier with external linkage, per
7.5p2.

7.1.3p2 <snip> If the program declares or defines an identifier in a
context in which it is reserved (other than as allowed by 7.1.4), or
defines a reserved
identifier as a macro name, the behavior is undefined.

and none of the exceptions in 7.1.4 covers errno, so declaring it,
even without defining, is UB; for exactly the reasons others have
answered and you have discovered.
- David.Thompson1 at worldnet.att.net



Relevant Pages

  • Re: Changes to stdlib.h from ver. 6.0 to ver. 8.0
    ... typedef struct TSK_Obj { ... "errno" is a macro that expands to a function call. ... shouldn't have used the name "errno" in the first place. ... order to access an actual object, or a program defines an identifier ...
    (microsoft.public.vc.language)
  • Re: Handling initializer element not constant error
    ... Obviously "errno" is an identifier. ... macro that doesn't have to expand to an identifier. ... It might not expand to the name of a variable at all. ...
    (comp.lang.c)
  • Re: Handling initializer element not constant error
    ... Obviously "errno" is an identifier. ... macro that doesn't have to expand to an identifier. ... It might not expand to the name of a variable at all. ...
    (comp.lang.c)
  • Re: Cleanup patterns
    ... In particular, if the function opens a number of resources, these need ... which uses the global errno to store ... them (macro ... set error code to success right before the cleanup ...
    (comp.lang.c)
  • Re: Macro redefinition
    ... forget to #undef EXPAND_DEF before redefining it. ... An identifier currently defined as an object-like macro shall not ... two replacement lists are identical. ...
    (comp.lang.c)