Re: NEWBIE: NSArray toll-free-bridged with CFArray?
Re: NEWBIE: NSArray toll-free-bridged with CFArray?
- Subject: Re: NEWBIE: NSArray toll-free-bridged with CFArray?
- From: Andrew Pinski <email@hidden>
- Date: Sun, 8 Sep 2002 00:24:21 -0400
On Sunday, Sep 8, 2002, at 00:01 US/Eastern, Mike Shields wrote:
On Saturday, September 7, 2002, at 06:25 PM, ber wrote:
Thanks Andreas,
I'm assuming at this point even if things are 'toll-free-bridged' one
can expect
the compiler to still complain.
brian
Yes, NSArray and CFArray are toll-free bridged, but that's an
implementation detail. There's no method for the _compiler_ to
determine that a CFArray == an NSArray, so you have to typecast.
Here's an example to illustrate what I mean.
typedef struct _Foo
{
char a;
char b;
char c;
char d;
} Foo;
typedef struct _Bar
{
char a;
char b;
char c;
char d;
} Bar;
These two structs are identical and in my little fantasy world they
contain the same information and mean the same things semantically.
But from the compiler's point of view, they have no relation to each
other so if I wanted to do this:
Foo* aFooPtr;
Bar aBar;
aFooPtr = &aBar;
The compiler would complain since I'm trying to assign a pointer of
one type to a pointer of another type. This is the same thing that's
going on with NSArray and CFArray.
The reason the compiler will complain is because the two structs are in
two different aliasing sets (aka they cannot have the same address, so
the compile can optimize away some of the instructions if it wants to).
Hope this clears up some of the problems that might end up being caused
with casts period (casts are bad, try using unions instead).
Thanks,
Andrew Pinski
Hope this clears every thing up for you.
Mike
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.