<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jun 19, 2013, at 11:45 PM, "Adler, Arik" <<a href="mailto:arik.adler@intel.com">arik.adler@intel.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="WordSection1" style="page: WordSection1;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Another alternative is to copy the pointer and not the whole array (as it done in C)</span></div></div></div></blockquote><div><br></div>But this is not the same as capturing the array.</div><div>You can get the effect you mentioned by declaring it as __block. Or you can capture the array by putting it in a struct and</div><div>capturing the struct instead.</div><div><br></div><div>- Fariborz</div><div><br><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="WordSection1" style="page: WordSection1;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"><o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;"><span class="Apple-converted-space"> </span>Eli Friedman [<a href="mailto:eli.friedman@gmail.com" style="color: purple; text-decoration: underline;">mailto:eli.friedman@gmail.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>Wednesday, June 19, 2013 20:46<br><b>To:</b><span class="Apple-converted-space"> </span>Adler, Arik<br><b>Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:cfe-dev@cs.uiuc.edu" style="color: purple; text-decoration: underline;">cfe-dev@cs.uiuc.edu</a><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: [cfe-dev] Question about arrays in blocks<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">On Wed, Jun 19, 2013 at 2:53 AM, Adler, Arik <<a href="mailto:arik.adler@intel.com" target="_blank" style="color: purple; text-decoration: underline;">arik.adler@intel.com</a>> wrote:<o:p></o:p></div><div><blockquote style="border-style: none none none solid; border-left-color: rgb(204, 204, 204); border-left-width: 1pt; padding: 0in 0in 0in 6pt; margin-left: 4.8pt; margin-right: 0in;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">I am now testing blocks usage in OpenCL.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">I noticed that Clang forbids using an arrays within blocks (Clang forbid array capturing)</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">For Example, the following code will fail to compile because there is a reference to an array within a block.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">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.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas; color: blue;">void</span><span style="font-size: 9.5pt; font-family: Consolas;"><span class="Apple-converted-space"> </span>block_arr()</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">{</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;"> <span class="Apple-converted-space"> </span><span style="color: blue;">int</span><span class="Apple-converted-space"> </span>res = 0;</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;"> <span class="Apple-converted-space"> </span><span style="color: blue;">int</span><span class="Apple-converted-space"> </span>i[4] = { 3, 4, 4, 1 };</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;"> <span class="Apple-converted-space"> </span><span style="color: blue;">int</span>* j = i;</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">  <span style="color: blue;">int</span><span class="Apple-converted-space"> </span>(^test_block )(<span style="color: blue;">int</span>) = ^(<span style="color: blue;">int</span><span class="Apple-converted-space"> </span>num)</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">    {</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">     <span class="Apple-converted-space"> </span><span style="color: blue;">return</span><span class="Apple-converted-space"> </span>num + i[1];     <span class="Apple-converted-space"> </span><span style="color: green;">// This is an error: "error: cannot refer to declaration with an array type inside block"</span></span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas; color: green;">//      return num + j[1];    // This would work</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">    };</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">    res = test_block(7);</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt 1in; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 9.5pt; font-family: Consolas;">}</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Do you know what is the reason behind this limitation?</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">And why it is possible to use a regular pointers but arrays are forbidden?</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div></blockquote><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">IIRC, it's just so that people don't accidentally make implicit copies of large arrays.<o:p></o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">-Eli <o:p></o:p></div></div></div></div></div><p>---------------------------------------------------------------------<br>Intel Israel (74) Limited</p><p>This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.</p></div></blockquote></div><br></body></html>