Re: Changes to stdlib.h from ver. 6.0 to ver. 8.0



al-s <eastlocust@xxxxxxxxx> wrote:
A project that builds without issue using VC++ ver. 6.0 has errors
when importing it into ver. 8.0 (VS2005).



I get the following error: error C2032: '_errno' : function cannot be
member of struct 'TSK_Obj' C:\spox60\INCLUDE\tsk.h 117

The so-called offending line is part of the C struct below:

typedef struct TSK_Obj {
Int errno; /* TSK_seterr()/TSK_geterr() */ <---- Error points to this
line
} TSK_Obj, *TSK_Handle;

"errno" is a macro that expands to a function call. After this
expansion, the line in question doesn't make any sense.

The bug is not in the standard headers, but in your program. It
shouldn't have used the name "errno" in the first place. From C99
standard:

7.5/2 It is unspecified whether errno is a macro or an identifier
declared with external linkage. If a macro definition is suppressed in
order to access an actual object, or a program defines an identifier
with the name errno, the behavior is undefined.

I suggest you simply give the field a different name.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • 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: declaring errno
    ... > I see in the standard that errno may be a macro, ... > definition since it doesn't reserve storage. ... Each identifier with file scope listed in any of the following ...
    (comp.lang.c)
  • Re: sequence points and evaluation order
    ... When it says "operand uses errno" does it mean reads ... a sequence point on calling a function, and the two calls are not ... If either call sets errno it is guaranteed that errno will ... If logis implemented as a macro, there may not be a sequence point. ...
    (comp.lang.c)
  • Re: detecting symbolic links in c
    ... How do you know errno can never be ... > a macro encapsulating a function? ... So, I guess it is not a good idea for me to declare it, after all. ... And of course, "extern int errno" is not technically a definition, so it ...
    (comp.unix.programmer)
  • 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)