[cfe-dev] Question about arrays in blocks

Adler, Arik arik.adler at intel.com
Wed Jun 19 23:45:12 PDT 2013


Another alternative is to copy the pointer and not the whole array (as it done in C)


From: Eli Friedman [mailto:eli.friedman at gmail.com]
Sent: Wednesday, June 19, 2013 20:46
To: Adler, Arik
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] Question about arrays in blocks

On Wed, Jun 19, 2013 at 2:53 AM, Adler, Arik <arik.adler at intel.com<mailto:arik.adler at intel.com>> wrote:

I am now testing blocks usage in OpenCL.
I noticed that Clang forbids using an arrays within blocks (Clang forbid array capturing)

For Example, the following code will fail to compile because there is a reference to an array within a block.
But if the line referring to block will comment out and the line with reference to integer pointer ('j') will comment in, the code will pass.

void block_arr()
{
  int res = 0;
  int i[4] = { 3, 4, 4, 1 };
  int* j = i;

  int (^test_block )(int) = ^(int num)
    {
      return num + i[1];      // This is an error: "error: cannot refer to declaration with an array type inside block"
//      return num + j[1];    // This would work
    };

    res = test_block(7);
}


Do you know what is the reason behind this limitation?
And why it is possible to use a regular pointers but arrays are forbidden?


IIRC, it's just so that people don't accidentally make implicit copies of large arrays.

-Eli
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130620/fb317eb0/attachment.html>


More information about the cfe-dev mailing list