Re: Method not seeing array as array
Re: Method not seeing array as array
- Subject: Re: Method not seeing array as array
- From: Gregory Weston <email@hidden>
- Date: Fri, 4 Feb 2005 07:08:40 -0500
On Feb 4, 2005, at 2:28 AM, Jeff Laing wrote:
The problem with "if (!self)" is that you're assuming that
nil is equal to zero.
(snip)
No, thats not the problem.
/usr/include/objc/objc.h. lines 51-57:
#ifndef nil
#define nil 0 /* id of Nil instance */
#endif
As for documentation, according to the objective-C language overview
"The keyword nil is defined as a null object, an id with a value of 0.
Ok, there's a bug for you then. The above header does *not* define nil
as
"an id with ..." - instead, its "an integer with ..."
If you implement to the word of the spec, you'd have
#ifndef nil
#define nil ((id)0)
#endif
which strict type-checking compilers may well barf on since ! is not a
defined operation for pointer types. Or is it?
I've seen C++ compilers that definitely reject this sort of thing, but
some
skate along on the lazy assumptions that says that the literal 0 is
type-compatible with any pointer, and they define !x as ( x != 0 ).
That's not lazy. That's proper. I don't have the spec in arms' reach to
cite, but the language reference is nearby and says:
"Because of standard conversions,0 can be used as a constant of any
integral, floating-point, pointer or pointer-to-member type. ... No
object is allocated with address 0. Consequently, 0 acts as a pointer
literal, indicating that the pointer doesn't refer to an object."
And for completeness, the C language ref says: "Pointers and integers
are not interchangeable. Zero is the sole exception: the constant zero
may be assigned to a pointer, and a pointer may be compared with the
constant zero."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden