<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Cannot pass array of constant size to a function as a reference</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/</id><updated>2024-01-09T13:10:46.760000Z</updated><subtitle>Recent posts to Cannot pass array of constant size to a function as a reference</subtitle><entry><title>Cannot pass array of constant size to a function as a reference</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/?limit=50#0e66" rel="alternate"/><published>2024-01-09T13:10:46.760000Z</published><updated>2024-01-09T13:10:46.760000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.comff8163cd52d1480c81d0f3f2e3c278186fe44c19</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;It will be a reference, because it's a VAR_IN_OUT.&lt;/p&gt;
&lt;p&gt;it's a little weird debugging the array online.  It just shows as a POINTER TO INT, and you can't actually see the array from the function side.  But you can still work with it as a normal array, not a pointer.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Cannot pass array of constant size to a function as a reference</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/?limit=25#645d/1035" rel="alternate"/><published>2024-01-09T05:00:37.198000Z</published><updated>2024-01-09T05:00:37.198000Z</updated><author><name>apurv</name><uri>https://forge.codesys.com/u/apurv/</uri></author><id>https://forge.codesys.com6952b18d6428c2ac54b85ff95c7b5776b8d55d62</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;okay but will this pass the array by copying it or it will be a reference to original array only.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Cannot pass array of constant size to a function as a reference</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/?limit=50#645d" rel="alternate"/><published>2024-01-08T14:32:22.323000Z</published><updated>2024-01-08T14:32:22.323000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com2ffed96c4d7f3c06df7f59073ac0b679062aa88e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;maybe this would be a better approach, then you don't have to pass the constant at all.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;FUNCTION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;fun&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;INT&lt;/span&gt;
&lt;span class="nt"&gt;VAR_IN_OUT&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;ARRAY&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;OF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;lower&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nt"&gt;DINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;upper&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nt"&gt;DINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="nt"&gt;lower&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;LOWER_BOUND&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;upper&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;UPPER_BOUND&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;see here as well&lt;br/&gt;
&lt;a href="https://help.codesys.com/api-content/2/codesys/3.5.13.0/en/_cds_vartypes_var_in_out/#constant-input-and-output-variable" rel="nofollow"&gt;https://help.codesys.com/api-content/2/codesys/3.5.13.0/en/_cds_vartypes_var_in_out/#constant-input-and-output-variable&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Cannot pass array of constant size to a function as a reference</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/?limit=25#0d04" rel="alternate"/><published>2024-01-08T05:13:45.020000Z</published><updated>2024-01-08T05:13:45.020000Z</updated><author><name>apurv</name><uri>https://forge.codesys.com/u/apurv/</uri></author><id>https://forge.codesys.com2a74563832dcc81ab1f6fb059cd2de52e17663f9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Could not find the solution to this issue but I have side stepped this by creating a global variable MAX_SIZE.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Cannot pass array of constant size to a function as a reference</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e8a02ace95/?limit=25#41dd" rel="alternate"/><published>2024-01-07T09:54:22.555000Z</published><updated>2024-01-07T09:54:22.555000Z</updated><author><name>apurv</name><uri>https://forge.codesys.com/u/apurv/</uri></author><id>https://forge.codesys.comfa293878e3aa94fa117170520ed990d23a4cab26</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have a Array of constant size defined like this &lt;br/&gt;
`&lt;br/&gt;
Var Constant&lt;br/&gt;
MAX_SIZE :UINT := 10;&lt;br/&gt;
End_var&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
array : ARRAY&lt;span&gt;[0..MAX_SIZE]&lt;/span&gt; OF INT;&lt;br/&gt;
END_VAR&lt;br/&gt;
`&lt;/p&gt;
&lt;p&gt;Now I want to pass this array to a function by reference, &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;Function&lt;/span&gt; &lt;span class="n"&gt;fun&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt;
&lt;span class="kr"&gt;VAR&lt;/span&gt; &lt;span class="n"&gt;IN_OUT&lt;/span&gt; &lt;span class="n"&gt;CONSTANT&lt;/span&gt;
&lt;span class="n"&gt;MAX_SIZE&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;UINT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;span class="n"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;REFERENCE&lt;/span&gt; &lt;span class="kr"&gt;TO&lt;/span&gt; &lt;span class="kr"&gt;ARRAY&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="n"&gt;MAX_SIZE&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kr"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;but when I run this it gives strange Errors &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;Error&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Cannot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Convert&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'ARRAY [0..MAX_SIZE] OF INT to type '&lt;/span&gt;&lt;span class="n"&gt;ARRAY&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;MAX_SIZE&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;OF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;INT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</summary></entry></feed>