Thankyou everybody for your help (and patience!) with this one. I have indeed 
been making some wrong assumptions and as I result much of what I was writing 
was incorrect. From the various helpful replies I have received, I have (I 
hope!) got a much clearer understanding of what is and isn't going on.

I now think that what I am seeing is a minor parsing sort of issue within the 
compiler (gcc 4.2) when mixing id<SomeProtocol> with blocks. In the example 
code below, everything works ok except for two lines, which lead to compile 
errors. [The mention of 'const' in the error was what was leading to my 
incorrect claims earlier, since that had got me thinking the problem was 
related to how you can't by default modify variables declared outside blocks. 
Sorry!].

I believe the compiler should not be objecting to the lines that it reports 
errors for...
Jonny

===== BEGIN CODE =====

// Declare a class with a property
@interface MyClass
        @property (readwrite) int frameNumber;
        -(int)frameNumber2;             // Try declaring a straight function 
just to see if it makes a difference
@end

void foo(MyClass *m)
{
        printf("%d %d n", m.frameNumber, m.frameNumber2);               // ok
        
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
        ^{
                printf("%d %d\n", m.frameNumber, m.frameNumber2);       // ok
        });
}

// Try the same, but with a protocol rather than a concrete class type
@protocol MyProtocol
        @property (readwrite) int frameNumber;
        -(int)frameNumber2;
@end

void foo2(id<MyProtocol> m)
{
        printf("%d %d n", m.frameNumber, m.frameNumber2);               // ok
        printf("%d %d\n", [m frameNumber], [m frameNumber2]);   // ok
        
        
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
        ^{
                // Both these have errors: "request for member 'frameNumber' in 
'm', which is of non-class type 'objc_object* const'"
                // when compiled as ObjC++ (.mm file).
                // I get a different error: "request for member 'frameNumber' 
in something not a structure or union"
                // when compiled as ObjC (.m file).
                printf("%d\n", m.frameNumber);
                printf("%d\n", m.frameNumber2);
                // Both these are ok
                printf("%d %d\n", [m frameNumber], [m frameNumber2]);
        });
}

===== END CODE =====

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to