void foo(void)
{
 static int *my_errno=NULL;
 if(my_errno==NULL) my_errno=errno;
 // code that uses 'my_errno' as if it were 'errno'
}

No, this is not legal code under the POSIX standard at all.

Since this code is single-threaded only, what POSIX standard are you talking
about? The pthreads standard doesn't apply.

In any event, provided the code is compiled single-threaded and
thread-safety has not been asked for, it's a perfectly legal compiler
optimization under the 'as-if' rule. No compliant code could ever tell the
difference.

Remember, I was not suggesting anyone actually write this code. I was
suggesting it was a legal compiler optimization so long as the code was not
compiled multi-threaded.

My point is very similar, nothing requires the platform to generate
thread-safe code if you don't ask it to. If it just happens to, it's purely
by accident.

Well, I'm late to this discussion, but it would seem to me that quite
a few things are wrong with that ...
First, my_errno=&errno;  might be more appropriate, after all, you need
to reference the address of errno, not the current value, right? But that
would also assume errno is declared as an int.  Some implementations,
like glibc, in bits/errno.h define errno as  #define errno (*__errno_location())
... so doing what you suggest wouldn't exactly be legal.

So assuming your system really declares errno as an int, and not a
define to a function, you wouldn't just be able to use 'my_errno'
instead of errno ... maybe (*my_errno), since obviously, you can't
forget to dereference it, right?

-Brad
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       openssl-dev@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to