<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Static variable initialization in Embedded C' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Static variable initialization in Embedded C' posted on the 'Embedded C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 12:14:47 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 12:14:47 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Static variable initialization in Embedded C</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/371232/371232/static-variable-initialization-in-embedded-c/</link>
      <description>I'm kind of confused about the static variable initialization in embedded C. In ANSI C they are not auto-initialized, meaning, you need to initialize them manually, although some compilers do this for you. How about embedded C? Is it universally agreed that all embedded C compilers will do the auto-initialization, or still case-by-case?</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/371232/371232/static-variable-initialization-in-embedded-c/</guid>
      <pubDate>Tue, 15 Apr 2008 19:35:16 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
    <item>
      <title>Re: Static variable initialization in Embedded C</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/371232/371243/re-static-variable-initialization-in-embedded-c/#371243</link>
      <description>First of all in ISO C (ANSI C), all static and global variables &lt;em&gt;must&lt;/em&gt; be initialized before the program starts. If the programmer didn't do this explicitly, then the compiler must set them to zero. If the compiler doesn't do this, it doesn't follow ISO C. Exactly &lt;em&gt;how&lt;/em&gt; the variables are initialized is however unspecified by the standard.&lt;br /&gt;
&lt;br /&gt;
So if the embedded compiler claims to be ISO C compatible, it must initialize statics (and globals) at startup. Since many embedded systems are ROM-based rather than RAM-based, it means that the compiler has to put code in the beginning of the program copying values from the ROM to the RAM.&lt;br /&gt;
&lt;br /&gt;
There are two problems appearing because of this: &lt;br /&gt;
&lt;br /&gt;
- You get a load of code in the beginning of your program, causing program startup to be slower. &lt;br /&gt;
&lt;br /&gt;
- In safety-critical realtime systems (or in any bug-free system), it is poor practice to rely on variables in RAM. From the point of initialization to the first time that variable is used, weeks or years might have passed. This isn't a programming problem, it is a hardware problem: RAM memory tends to be volatile and untrustworthy.&lt;br /&gt;
&lt;br /&gt;
The only solution to these problems is to write the code so that all initialization of statics/globals is done in runtime, just before the variable is used. Once this is done, you can usually disable the "copy-down" functionality of the compiler. That way you can remain ISO C compatible while your program gets faster and safer.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/371232/371243/re-static-variable-initialization-in-embedded-c/#371243</guid>
      <pubDate>Tue, 15 Apr 2008 23:39:53 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
    <item>
      <title>Re: Static variable initialization in Embedded C</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/371232/371436/re-static-variable-initialization-in-embedded-c/#371436</link>
      <description>Thank you for your explanation. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/371232/371436/re-static-variable-initialization-in-embedded-c/#371436</guid>
      <pubDate>Wed, 23 Apr 2008 19:10:49 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
  </channel>
</rss>