<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/</id><updated>2020-10-15T10:35:29.689000Z</updated><subtitle>Recent posts to Assigning to a dereferenced pointer</subtitle><entry><title>Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/?limit=250#fef2/4318/0495/2ff8" rel="alternate"/><published>2020-10-15T10:35:29.689000Z</published><updated>2020-10-15T10:35:29.689000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com85d5e49b39406c0aa70804af43dad4f7c580a813</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ah, I never considered that. But pointers should do fine if you check them &amp;lt;&amp;gt; 0 before trying to dereference them.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/?limit=25#fef2/4318/0495" rel="alternate"/><published>2020-10-15T10:16:47.629000Z</published><updated>2020-10-15T10:16:47.629000Z</updated><author><name>jsaxin</name><uri>https://forge.codesys.com/u/jsaxin/</uri></author><id>https://forge.codesys.com193cc55e9abe4806999ede0410b0d7f031b2148b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Alas, it turns out references cannot be put into arrays. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/?limit=25#fef2/4318/0e46" rel="alternate"/><published>2020-10-15T09:22:18.812000Z</published><updated>2020-10-15T09:22:18.812000Z</updated><author><name>jsaxin</name><uri>https://forge.codesys.com/u/jsaxin/</uri></author><id>https://forge.codesys.comda34a16b48845366ccc7e7a788a8645b78f08cca</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank you. I will look into references. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/?limit=250#fef2/4318" rel="alternate"/><published>2020-10-15T09:03:15.705000Z</published><updated>2020-10-15T09:03:15.705000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com1e4d4b052a29e09c5de403dcda8f0ee96fffb4f2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Some tips after seeing your code snippet:&lt;/p&gt;
&lt;p&gt;To ensure you always work with a valid pointer you should take care of the following: &lt;br/&gt;
Always call the code which references the pointer and not do this only once(!) Doing it continuously ensures correct working during a warm download after a code change, besides the overhead is minimal compared to a crashing application ;-) &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;xFirstCycle&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
    &lt;span class="nv"&gt;apwPointers&lt;/span&gt;[&lt;span class="mi"&gt;0&lt;/span&gt;] :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;ADR&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;LagerD&lt;/span&gt;.&lt;span class="nv"&gt;Evaporator1&lt;/span&gt;.&lt;span class="nv"&gt;iDefrostHour1&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;    &lt;span class="nv"&gt;xFirstCycle&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;FALSE&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Plus always test the validity of the pointer before dereferencing it, even if you are sure that it is initialised properly. &lt;br/&gt;
An escape is to rewrite your code using References, they are "equal" to pointers but are typesafe.&lt;/p&gt;
&lt;p&gt;Hope this helps you&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/?limit=25#fef2" rel="alternate"/><published>2020-10-15T08:31:15.321000Z</published><updated>2020-10-15T08:31:15.321000Z</updated><author><name>jsaxin</name><uri>https://forge.codesys.com/u/jsaxin/</uri></author><id>https://forge.codesys.com271cc6f2cee25602c05f496c78c25bf2247cfca2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have found that I never actually initiated the pointer. Please delete this thread. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assigning to a dereferenced pointer</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/d77de10193/?limit=25#7570" rel="alternate"/><published>2020-10-13T11:30:36.847000Z</published><updated>2020-10-13T11:30:36.847000Z</updated><author><name>jsaxin</name><uri>https://forge.codesys.com/u/jsaxin/</uri></author><id>https://forge.codesys.com217b075fa7bc3544d3c6d43502ce37ebbf57a9d8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have made an array of pointers to places in memory I would like to write to while treating them as a continuous block. But I cannot find the syntax for doing this as all examples of dereferencing has the pointer to the value being copied and not the one being overwritten. &lt;/p&gt;
&lt;p&gt;This triggers a runtime error: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;Slave&lt;/span&gt;.&lt;span class="nv"&gt;udiWriteAccessCounter&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;udiWriteCounter&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
    &lt;span class="nv"&gt;apwPointers&lt;/span&gt;[&lt;span class="nv"&gt;Slave&lt;/span&gt;.&lt;span class="nv"&gt;wWriteAddress&lt;/span&gt;]&lt;span class="o"&gt;^&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;awHoldingRegisters&lt;/span&gt;[&lt;span class="nv"&gt;Slave&lt;/span&gt;.&lt;span class="nv"&gt;wWriteAddress&lt;/span&gt;]&lt;span class="c1"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;udiWriteCounter&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Slave&lt;/span&gt;.&lt;span class="nv"&gt;udiWriteAccessCounter&lt;/span&gt;&lt;span class="c1"&gt;;     &lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry></feed>