<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>8-bit Microcontrollers中的主题 Re: MC9S08SH16 - Local static variable initialization</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170990#M11474</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is what I&amp;nbsp;think&amp;nbsp;myself&amp;nbsp;- that it is a compiler settings that&amp;nbsp;distinguishes&amp;nbsp;between the globals and the&amp;nbsp;static&amp;nbsp;variables initialization at startup. I kinda&amp;nbsp;inherited&amp;nbsp;the project and I have to continue with what I got but I will try your suggestion to generate another project to see if the warning persists.&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jan 2010 21:40:48 GMT</pubDate>
    <dc:creator>Octavian_D_Iosu</dc:creator>
    <dc:date>2010-01-29T21:40:48Z</dc:date>
    <item>
      <title>MC9S08SH16 - Local static variable initialization</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170986#M11470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am relatively new to Freescale micros and CodeWarrior. I currently work at a project that uses a MC9S08SH16 micro and I have a question about variable initialization at start-up.&lt;/P&gt;&lt;P&gt;I used the following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define&amp;nbsp;DEFINED_VAR &lt;SPAN class="Apple-tab-span"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void nameFunction1(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;static unsigned char var1 = DEFINED_VAR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if(var1 != 0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;--var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;var1 = DEFINED_VAR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;nameFunction2(); /* function call */&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;} /* end of function */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At compile time &amp;nbsp;I got the following warning&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;L1981: &amp;nbsp;No copydown created for&amp;nbsp;initialized object "var1.4". Initialization data lost.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically at start-up &amp;nbsp;the var1 was&amp;nbsp;initialized&amp;nbsp;to 0 and the "else" branch was executed immediately even tough that was not the intention.&lt;/P&gt;&lt;P&gt;I realize that are work around solutions for this particular example but I would like to understand why this warning message in showed up the first place and what settings must be enabled in the project such that the static local variable gets initialized at start-up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your consideration&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2010 05:15:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170986#M11470</guid>
      <dc:creator>Octavian_D_Iosu</dc:creator>
      <dc:date>2010-01-29T05:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08SH16 - Local static variable initialization</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170987#M11471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Octavian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this the code you actually compiled?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code as listed appears to have a syntax error since you have defined DEFINE_VAR as nothing!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The line&lt;/P&gt;&lt;P&gt;&amp;nbsp;static unsigned char var1 = DEFINED_VAR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would translate as :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;static unsigned char var1 = ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which would be a syntax error other than the one you indicate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Changing the #define line to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define DEFINED_VAR&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;results in no errors or warnings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, are you using ANSI Startup Code option in the new Project Wizard? This would be necessary to initialise static variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2010 07:01:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170987#M11471</guid>
      <dc:creator>pgo</dc:creator>
      <dc:date>2010-01-29T07:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08SH16 - Local static variable initialization</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170988#M11472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;My mistake...&lt;/P&gt;&lt;P&gt;the code snippet was just an example and I forgot to assign a value to DEFINED_VAR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the&amp;nbsp;actual&amp;nbsp;code I did assign a value to my #define.&lt;/P&gt;&lt;P&gt;Also the compiler has been set up to generate start-up code using ANSI and not minimal requirements and yet I still got the warning message L1981.&lt;/P&gt;&lt;P&gt;After reading some Help documentation and looking at the map file I think it has to do with how the&amp;nbsp;variables&amp;nbsp;are allocated in the memory at startup (data is copied from ROM to RAM).&lt;/P&gt;&lt;P&gt;If I would have declared my variable global ( static implied) the warning&amp;nbsp;would not&amp;nbsp;have showed up but I tried to minimize the number of the global variable used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your consideration&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2010 13:18:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170988#M11472</guid>
      <dc:creator>Octavian_D_Iosu</dc:creator>
      <dc:date>2010-01-29T13:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08SH16 - Local static variable initialization</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170989#M11473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As far as the initialization is concerned, static locals and globals behave the same.&lt;/P&gt;&lt;P&gt;The question is why does the linker drop the initialization data, and for this only the minimal startup option or in general the lack of startup code comes to mind.&lt;/P&gt;&lt;P&gt;Can you try the same in a newly created project? I think in your setup something got changed which&lt;/P&gt;&lt;P&gt;broke the global initialization (maybe intentionally).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2010 17:44:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170989#M11473</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-01-29T17:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08SH16 - Local static variable initialization</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170990#M11474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is what I&amp;nbsp;think&amp;nbsp;myself&amp;nbsp;- that it is a compiler settings that&amp;nbsp;distinguishes&amp;nbsp;between the globals and the&amp;nbsp;static&amp;nbsp;variables initialization at startup. I kinda&amp;nbsp;inherited&amp;nbsp;the project and I have to continue with what I got but I will try your suggestion to generate another project to see if the warning persists.&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2010 21:40:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170990#M11474</guid>
      <dc:creator>Octavian_D_Iosu</dc:creator>
      <dc:date>2010-01-29T21:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: MC9S08SH16 - Local static variable initialization</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170991#M11475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When rereading the post I thought of another reason, apart from disabled startup code, to get the dropped initialization data.&lt;/P&gt;&lt;P&gt;The linker supports different segment types, only READ_WRITE segments get initialized by the copy down. If any variable gets allocated into another type (NO_INIT or PAGED) segment, that variables initialization data is dropped.&lt;/P&gt;&lt;P&gt;So into what kind of segment is the variable you experienced the issue placed?&lt;/P&gt;&lt;P&gt;Not sure out of memory, but it is possible that static locals and globals are placed by default into different ELF sections and therefore can be placed into different segments in the prm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW: To make the list of segment types complete, if a variable gets allocated in a READ_ONLY segment, then the variable is initialized during download, not during startup. This is typically used placing constants into flash or EEPROM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Jan 2010 01:55:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/MC9S08SH16-Local-static-variable-initialization/m-p/170991#M11475</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-01-31T01:55:50Z</dc:date>
    </item>
  </channel>
</rss>

