Re: Necessity of multi-level error propogation
* Jeff Schwab:
James Kanze wrote:
* Jeff Schwab:
errno isn't a global variable
It certainly behaves like one.
Not really. For example, variable names respect scopes, but errno does
not.
You are again choosing a contextually non-sensical meaning of a term.
It's just silly.
Stop.
Someone who really thinks errno is a global variable will have a
heck of a time debugging the following code:
Sorry, but here is a counter-example to that unfounded assertion. I really know
(which includes really think) that errno is a global variable. I wouldn't debug
the code since it's very obvious code, but if I had to debug it I wouldn't have
any problem with that either.
Now, a blanket assertion is proven false if there is any counter-example whatsoever.
The above is a counter-example.
#include <errno.h>
class errno_exception
{
int m_errno;
public:
errno_exception( int errno )
: m_errno( errno ) { }
int errno() const {
return m_errno;
}
};
There is no problem understanding this code in C++ since in C++ errno is known
to be a macro.
It's also a global variable. :-)
And for a multi-threaded program it's usually implemented as thread-local storage.
In fact, the latter works in GCC 4, if and only if <errno.h> is removed.
Depends what you mean by "works" and "removed".
Regarding the latter I'll assume the least ureasonable meaning I can think of,
namely that you're talking about removing the #include directive.
In that case the code, when present in a complete program, may still not compile
due to [errno.h] being dragged in by some other header, which means, considering
the "if and only if", that by "works" you presumably mean "can be made to
compile and yield the same result as if 'errno' was replaced by 'x'".
Yes, it's a stretch to assume this meaning, by I'm trying to accomodate you by
choosing the least unreasonable meaning I can think of. ;-)
Do you still not see?
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!