Re: static acting like __block in GCD singleton pattern

2013-07-01 Thread Matt Neuburg
Very nice, thanks! m. On Jul 1, 2013, at 10:42 AM, John McCall wrote: > On Jun 30, 2013, at 9:47 AM, Alex Zavatone wrote: >> On Jun 29, 2013, at 12:20 PM, Matt Neuburg wrote: >>> Yes, I looked at the spec and searched on the word "static" but I can't >>> really understand what the spec is tell

Re: static acting like __block in GCD singleton pattern

2013-07-01 Thread John McCall
On Jun 30, 2013, at 9:47 AM, Alex Zavatone wrote: > On Jun 29, 2013, at 12:20 PM, Matt Neuburg wrote: >> Yes, I looked at the spec and searched on the word "static" but I can't >> really understand what the spec is telling me. Am I the only one who thinks >> that this document has gotten more an

Re: static acting like __block in GCD singleton pattern

2013-07-01 Thread Steve Sisak
At 9:20 AM -0700 6/29/13, Matt Neuburg wrote: On Jun 28, 2013, at 5:26 PM, Kyle Sluder wrote: > On Fri, Jun 28, 2013, at 05:17 PM, Matt Neuburg wrote: Why is the block permitted to assign to the variable sharedInstance outside the block? Evidently it is because "static" has an effect like "

Re: static acting like __block in GCD singleton pattern

2013-06-30 Thread Alex Zavatone
On Jun 29, 2013, at 12:20 PM, Matt Neuburg wrote: > > Yes, I looked at the spec and searched on the word "static" but I can't > really understand what the spec is telling me. Am I the only one who thinks > that this document has gotten more and more obscure and abstruse over time? So I'm not

Re: static acting like __block in GCD singleton pattern

2013-06-29 Thread Matt Neuburg
That is *extremely* clear - thanks! m. On Jun 29, 2013, at 9:42 AM, Jens Alfke wrote: > > On Jun 29, 2013, at 9:20 AM, Matt Neuburg wrote: > >> I'm trying to come up with a pithy explanation, suitable for beginners, of >> why a "static" variable doesn't need a "__block" specifier in order fo

Re: static acting like __block in GCD singleton pattern

2013-06-29 Thread Matt Neuburg
On Jun 29, 2013, at 10:00 AM, Kyle Sluder wrote: > In the first case, the block context captured the _value_ of a. In the > second, it captured the _pointer to b's movable storage_. That's a nice example, because it also focuses on the *other* practical aspect of __block, namely that it causes

Re: static acting like __block in GCD singleton pattern

2013-06-29 Thread Kyle Sluder
On Sat, Jun 29, 2013, at 09:53 AM, Kyle Sluder wrote: > Yes. In order to make it possible to capture local variables in a block, > they are potentially hoisted to a storage that has the same lifetime as > the block. For readonly accesses, that doesn't matter; the value of the > expression is captur

Re: static acting like __block in GCD singleton pattern

2013-06-29 Thread Kyle Sluder
On Sat, Jun 29, 2013, at 09:20 AM, Matt Neuburg wrote: > I take it that the distinction we're drawing here is between static > storage (which happens at file level and is therefore permanent) Nitpick: static _storage_ doesn't have anything to do with the _file_. The `static` keyword applied to a v

Re: static acting like __block in GCD singleton pattern

2013-06-29 Thread Jens Alfke
On Jun 29, 2013, at 9:20 AM, Matt Neuburg wrote: > I'm trying to come up with a pithy explanation, suitable for beginners, of > why a "static" variable doesn't need a "__block" specifier in order for a > block to assign to it. The word "captured", as you suggest, may be useful > here, since t

Re: static acting like __block in GCD singleton pattern

2013-06-29 Thread Matt Neuburg
On Jun 28, 2013, at 5:26 PM, Kyle Sluder wrote: > On Fri, Jun 28, 2013, at 05:17 PM, Matt Neuburg wrote: >> Why is the block permitted to assign to the variable sharedInstance >> outside the block? Evidently it is because "static" has an effect like >> "__block", in that it makes the variable ou

Re: static acting like __block in GCD singleton pattern

2013-06-28 Thread Kyle Sluder
On Fri, Jun 28, 2013, at 05:17 PM, Matt Neuburg wrote: > Why is the block permitted to assign to the variable sharedInstance > outside the block? Evidently it is because "static" has an effect like > "__block", in that it makes the variable outside the block assignable. > But how, exactly? Is it so

static acting like __block in GCD singleton pattern

2013-06-28 Thread Matt Neuburg
In this sort of well-known code pattern for making a singleton with GCD: + (MyClass *) sharedInstance { static MyClass *sharedInstance = nil; static dispatch_once_t onceToken = 0; dispatch_once (&onceToken, ^{ sharedInstance = [MyClass new]; }); return sharedInstance; }