<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Variable declaration GLOBAL vs LOCAL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/800a70db3f/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/800a70db3f/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/800a70db3f/</id><updated>2020-02-27T14:34:10.665000Z</updated><subtitle>Recent posts to Variable declaration GLOBAL vs LOCAL</subtitle><entry><title>Variable declaration GLOBAL vs LOCAL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/800a70db3f/?limit=25#8b16" rel="alternate"/><published>2020-02-27T14:34:10.665000Z</published><updated>2020-02-27T14:34:10.665000Z</updated><author><name>shouryapendyala</name><uri>https://forge.codesys.com/u/shouryapendyala/</uri></author><id>https://forge.codesys.comd9346dc75bca32eb59525ccdebd11665b16d30f0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks PrinceACP.&lt;/p&gt;
&lt;p&gt;I am aware of the debugging issues and possible complications with global variables. The only thing I was not sure about was the burden on the task cycle. Thanks again for your input.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable declaration GLOBAL vs LOCAL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/800a70db3f/?limit=25#24a6" rel="alternate"/><published>2020-02-27T14:34:10.192000Z</published><updated>2020-02-27T14:34:10.192000Z</updated><author><name>PrinceACP</name><uri>https://forge.codesys.com/u/princeacp/</uri></author><id>https://forge.codesys.com8f27f66239a42780cd0147be4c85ec6788c15fa2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Global variables are using memory the entire time your program is running. Local variables will only use memory when a corresponding POU is running/being called. So theoretically, from a performance point of view, all your variables being global will slow down execution.&lt;/p&gt;
&lt;p&gt;Most programmers and literature agree to minimise the use of global variables, largely because of how hard it is to debug and trace them. If you are using a global variable in multiple POUs, then to debug you have to follow the variable through each POU to find an issue. If you figure out a smart way to declare variables locally, then you can debug in just that POU, which is much easier.&lt;/p&gt;
&lt;p&gt;I have written programs in my early days that used a lot of global variables. I even used some Goto statements in some C-Programming projects at uni. These solutions I used were flawed, because at the time, they seemed like an easy solution. But in the long run, they cause many issues in debugging and make the code a lot more complex than it needs to be.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://en.wikibooks.org/wiki/A-level_Computing_2009/AQA/Problem_Solving,_Programming,_Data_Representation_and_Practical_Exercise/Fundamentals_of_Programming/Global_and_Local_Variables" rel="nofollow"&gt;https://en.wikibooks.org/wiki/A-level_C ... _Variables&lt;/a&gt; m &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable declaration GLOBAL vs LOCAL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/800a70db3f/?limit=25#56af" rel="alternate"/><published>2020-02-27T14:34:09.695000Z</published><updated>2020-02-27T14:34:09.695000Z</updated><author><name>shouryapendyala</name><uri>https://forge.codesys.com/u/shouryapendyala/</uri></author><id>https://forge.codesys.com62b7318beff9910b24744edf239d8c377c698b3e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Are there any pros and cons from performance standpoint? i.e,. does declaring all variables in global cause the task execution to take longer vs local declaration?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>