On May 31, 2012, at 2:00 PM, Jean-Daniel Dupas <[email protected]> wrote:

> Le 31 mai 2012 à 18:00, Jens Alfke a écrit :
> 
>> On May 31, 2012, at 8:47 AM, Antonio Nunes wrote:
>> 
>>> static void *kMyVLFContext = &kMyVLFContext;
>> ...  
>>>     @synchronized(kMyVLFContext) {
>> 
>> Huh? I thought the parameter to @synchronized(…) had to be an object 
>> reference?
> 
> 
> The Objective-C reference agree with you.
> 
> «The @synchronized() directive takes as its only argument any Objective-C 
> object, including self.»
> 
> http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocThreading.html%23//apple_ref/doc/uid/TP30001163-CH19-SW1
> 
> I'm surprised the compiler does not complain when passing an arbitrary 
> pointer.

That's because the compiler can't know it's invalid, due to the use of void * 
as the var type (void * pretty much matches everything, including id, must like 
id matches any object reference).

Suggestions:

1. remove the k prefix, by convention that is reserved for constants

2. don't use the same var name for a local variable as for a global variable

3. That should be something like:

static VLFContext* myVLFContext = nil;
...
        if( !myVLFContext )
                myVLFContext = [VLFContext alloc] init];
...
        @synchronized( myVLFContext ) {
        ...
        }



-lane

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to