Re: detecting symbolic links in c

From: Mac (foo_at_bar.net)
Date: 04/22/04


Date: Wed, 21 Apr 2004 20:48:45 -0700

On Mon, 19 Apr 2004 22:17:49 +0000, Brian Raiter wrote:

>> I agree with all your arguments except this last one. Errno isn't a
>> function, so different rules apply.
>
> On what do you base that assertion? How do you know errno can never be
> a macro encapsulating a function? For that matter, how do you know
> errno can never be a short? Or a long? Or unsigned, for that matter?
>
> Unless memory fails me, I don't believe ANSI or POSIX makes any promise
> other than that "errno" is some kind of object that can be compared
> with positive integral values. I'm not even sure it requires that
> errno be "non-const".
>
> b

>From the standard:

   The header <errno.h> defines several macros, [...] and

         errno

which expands to a modifiable lvalue/83/ that has type int , the value
of which is set to a positive error number by several library
functions. 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 external identifier with the name errno, the behavior is
undefined.

--------------end of quote-----------------------

So, I guess it is not a good idea for me to declare it, after all. Doing
so could result in a syntax error if errno is a macro. But it is clearly
intended to have integer-like behavior, since it is modifiable lvalue of
type int.

And of course, "extern int errno" is not technically a definition, so it
doesn't explicitly violate the text above.

I don't know what posix says about errno, but from now on I won't be
declaring it in any functions I write.

--Mac



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: 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: DLL & pointers problem
    ... there would be no need to declare the argument for ... >> Bob Hairgrove ... macro), or 'extern "C"' if the function is to have C linkage. ...
    (comp.lang.cpp)