• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: cannot access __block variable of array type inside block
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot access __block variable of array type inside block


  • Subject: Re: cannot access __block variable of array type inside block
  • From: Dave Zarzycki <email@hidden>
  • Date: Tue, 14 Dec 2010 19:35:24 -0800

Jonathon,

This is being tracked by our internal bug number 8590846. I'm told that the workaround is to place the array within a structure:

__block struct {
	double result[COUNT];
} results;


davez



On Dec 14, 2010, at 7:30 PM, Jonathon Kuo wrote:

> I'm trying to learn GCD and reading http://developer.apple.com/library/mac/#featuredarticles/BlocksGCD/index.html
> But the Global Concurrent Queues example in that document (last updated 2010-11-10) doesn't even compile. It complains about accessing array 'result' from within the block:
>
> #define COUNT 128
> __block double result[COUNT];
> dispatch_apply(COUNT, q_default, ^(size_t i){
> 	result[i] = complex_calculation(i);   /* <=== ERROR HERE!
> });
> double sum = 0;
> for (int i=0; i < COUNT; i++) sum += result[i];
>
>
> What is wrong here? This looks like it should work. Below is my full program.
> -Jonathon
>
>
> #include <dispatch/dispatch.h>
> #include <stdio.h>
> #define COUNT 128
>
> double complex_calculation( int i )
> {
>  return i * 3.14;
> }
>
> int main()
> {
>  int i = 0;
>  __block double result[COUNT];
>
>  dispatch_queue_t q_default;
>  /* get default queue */
>  q_default = dispatch_get_global_queue(0, 0);
>
>  dispatch_apply(COUNT, q_default, ^(size_t i) {
>    result[i] = complex_calculation(i);   /* <=== ERROR HERE!
>  });
>
>  double sum = 0;
>  for (i=0; i < COUNT; i++) sum += result[i];
>  printf("%f\n", sum);
>  return 0;
> }
>
> $ cc -g blk3.c -o blk3
> blk3.c: In function ‘__main_block_invoke_1’:
> blk3.c:20: error: cannot access __block variable of array type inside block
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: cannot access __block variable of array type inside block
      • From: Jonathon Kuo <email@hidden>
References: 
 >cannot access __block variable of array type inside block (From: Jonathon Kuo <email@hidden>)

  • Prev by Date: Intercepting cocoa/quartz/opengl Draw command.
  • Next by Date: Moderator - Reminder ALL first posts are moderated
  • Previous by thread: cannot access __block variable of array type inside block
  • Next by thread: Re: cannot access __block variable of array type inside block
  • Index(es):
    • Date
    • Thread