Re: ARC: cast C-array of CFTypeRef

  • On Jun 4, 2012, at 6:25 PM, Andreas Grosam wrote:

    >
    > On Jun 4, 2012, at 4:15 PM, Jim Dovey wrote:
    >
    >
    > Eventually, I got this to "compile". Note sure if this ends up with correct code, though:

    OK, this crashes badly, which is understandable :)

    But there seems no way to get the pointer to buffer and make a bridge cast:
        typedef CFTypeRef* cf_pointer;

        id __unsafe_unretained* o = (__bridge __unsafe_unretained id)(buffer);
                                    ^
    Error: Incompatible types casting 'cf_pointer' (aka 'const void **') to '__unsafe_unretained id' with a __bridge cast

    >
    >
    >
    >
    >>
    >> On 2012-06-04, at 9:47 AM, Andreas Grosam wrote:
    >>
    >>>
    >>> On Jun 4, 2012, at 3:40 PM, Remy Demarest wrote:
    >>>
    >>>> Use __bridge: (__bridge id *)buffer.
    >>>
    >>> No sorry, this doesn't work. The better way would have been
    >>>
    >>> (__bridge id __strong*)buffer
    >>>
    >>> but that doesn't work either.
    >>>
    >>> (both, issue compiler errors)
    >>>
    >>>
    >>>
    >>> Andreas
    >>>
    >>>>
    >>>> Remy "Psy" Demarest
    >>>>
    >>>> Le 04 juin 2012 à 09:32, Andreas Grosam a écrit :
    >>>>
    >>>>> Under ARC, how do I cast an array of CF objects to an array of id objects?
    >>>>>
    >>>>> CFTypeRef* buffer = (CFTypeRef*)malloc(N*sizeof(CFTypeRef));
    >>>>> for (int i = 0; i < N; ++i) {
    >>>>> buffer[i] = … ;
    >>>>> }
    >>>>>
    >>>>> For instance when passing the array of CF objects 'buffer' to a method which requires an array of id, e.g.:
    >>>>>
    >>>>> (non-ARC):
    >>>>> NSArray* array = [[NSArray alloc] initWithObjects:(id*)buffer count:N];
    >>>>>
    >>>>>
    >>>>>
    >>>>> Andreas
    >>>>> _______________________________________________
    >>>>> Do not post admin requests to the list. They will be ignored.
    >>>>> Objc-language mailing list      (<Objc-language...>)
    >>>>> Help/Unsubscribe/Update your Subscription:
    >>>>> https://lists.apple.com/mailman/options/objc-language/<remy.demarest...>
    .com

    >>>>>
    >>>>> This email sent to <remy.demarest...>
    >>>>
    >>>
    >>>
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Objc-language mailing list      (<Objc-language...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>> https://lists.apple.com/mailman/options/objc-language/<jimdovey...>
    >>>
    >>> This email sent to <jimdovey...>
    >>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Objc-language mailing list      (<Objc-language...>)
    > Help/Unsubscribe/Update your Subscription:
    > https://lists.apple.com/mailman/options/objc-language/<agrosam...>.
    de

    >
    > This email sent to <agrosam...>
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today