[cfe-dev] Question about arrays in blocks
Eli Friedman
eli.friedman at gmail.com
Wed Jun 19 10:45:44 PDT 2013
On Wed, Jun 19, 2013 at 2:53 AM, Adler, Arik <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130619/7cdfd5d0/attachment.html>
More information about the cfe-dev
mailing list