[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSLog() / NSLogv() annoyance
From: |
Chris B. Vetter |
Subject: |
Re: NSLog() / NSLogv() annoyance |
Date: |
Fri, 1 Aug 2003 09:55:04 -0700 |
On Fri, 1 Aug 2003 15:46:05 +0100
Richard Frith-Macdonald <richard@brainstorm.co.uk> wrote:
[...]
> I know you know this but ... it's easy to overlook when you are used
> to working with objects ... in C/ObjC, function arguments are passed
> by value rather than by reference.
> This means that if (the value of) errno is passed as an argument to
> NSLog, the value logged will be the original value passed irrespective
> of any changes to the contents of the errno
> variable which might be made inside NSLog itsself.
> Any other behavior is a compiler bug.
Yes, but check an earlier mail I sent. If you do a system call, then use
NSLog() to print some info regarding the call, and then check errno,
errno is set to 2, which is a bad thing (IMHO) since the error referred
to by errno is a result of calling NSLog() not the system call as you'd
expect. Example:
// error is zero on success, non-zero on failure and errno
// will be set to the actual error number...
error = getaddrinfo(hostname, NULL, &hints, &address);
if( 0 != error )
NSLog(@"getaddrinfo() for host %s returns: %s",
hostname, gai_strerror(errno));
// Now here we'll run into a problem...
switch( errno )
{
case EAI_ADDRFAMILY:
NSLog(@"address domain not supported");
return nil;
case EAI_AGAIN:
// temporary error, try again...
[...]
default:
// can't recover
return nil;
}
The problem here is, that by calling NSLog(), errno will be set to 2.
HOWEVER, EAI_AGAIN is (at least on BSD) also defined as 2.
You can imagine what will happen...
--
Chris