From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@9fans.net Date: Mon, 7 Sep 2009 09:06:57 +0000 From: comeau@panix.com (Greg Comeau) Message-ID: References: <8b3f8874fbb5ead75e41d071391448e9@quanstro.net>, <8214DB3A-3368-4B61-B0CD-BAC5F2BE7271@sun.com> Subject: Re: [9fans] "Blocks" in C Topicbox-Message-UUID: 67f25680-ead5-11e9-9d60-3106f5b1d025 In article <8214DB3A-3368-4B61-B0CD-BAC5F2BE7271@sun.com>, Roman Shaposhnik wrote: >There's been a *lot* of speculation on this thread and very little fact. >I'd encourage everybody to play with the feature before forming >any kind of final judgement. This is true, a good point, etc, however.... >On Sep 3, 2009, at 8:52 PM, erik quanstrom wrote: >>> Did you even read the article or any of the examples? There are >>> plenty >>> of things that you can "do" with blocks that you can't with just >>> function pointers. That's besides the fact that some of them are more >>> elegantly expressed with blocks that look sort of ugly with function >>> pointers. >> >> on the other hand, apple says this is illegal > >Where exactly does it say that? > >> dispatch_block_t p; >> >> if(cond){ >> p =^ { print("cond\n"); }; >> }else{ >> p =^ { print("cond\n"); }; >> } >> p(); >> >> since the first part is equivalent to >> >> if(cond){ >> struct Block _t = ...; >> p = &_t; >> } > >I'm pretty sure Apple's compiler is smart enough to allow the >construct that you've just mentioned. In fact, I'd be willing >to bet on it. .... I'm fairly certain I was confused about this when I originally read that document. I think (I can't recall) the example being in a different language than C so coughed it up to some different scoping rules or something in that other language. So, the clincher is, if it's the case, since it seems obvious that the construct could work the way one would intuitively?? think it would work, then, why doesn't it? -- Greg Comeau / 4.3.10.1 with C++0xisms now in beta! Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it?