<?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>CodeWarrior for MCUのトピックRe: C++ Constants going to SRAM</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699739#M14106</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've attached Demo.zip and the class A::TestClass::CVal is a constant declared in the header and defined in the CPP file and used in Main. DVal is declared and defined in the header and does not have the same issue as CVal.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Oct 2017 17:13:04 GMT</pubDate>
    <dc:creator>manishsangram</dc:creator>
    <dc:date>2017-10-10T17:13:04Z</dc:date>
    <item>
      <title>C++ Constants going to SRAM</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699737#M14104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are using &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;S12ZVMC128 and using Codewarior 10.6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;We were running out of SRAM and when looking into the matter by referring to the MAP file we realized that even though we have marked constants as static and const, these&amp;nbsp;are being treated as variables and are being put in SRAM.&amp;nbsp; This should not be the case because obviously a constant is a constant and should only reside in RO memory.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Example of how we have defined a constant is given below&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;CClassX.h&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;class X{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;static const unsigned char &lt;SPAN&gt;ConstantVal;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;};&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;CClassX.cpp&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;const unsigned char X::ConstantVal = 100;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is the compiler creating variables in SRAM for such constants?&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can we turn them off.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We checked that similar static constants outside class definition (module level) are correctly put only in RO so it cannot be any form of speed optimization.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-338624"&gt;Demo.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 13:56:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699737#M14104</guid>
      <dc:creator>manishsangram</dc:creator>
      <dc:date>2017-10-05T13:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: C++ Constants going to SRAM</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699738#M14105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Manish&lt;/P&gt;&lt;P&gt;To work on your problem more efficiently,Could you please upload your demo project? I will check it directly from my side.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jennie Zhang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Oct 2017 07:05:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699738#M14105</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2017-10-10T07:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: C++ Constants going to SRAM</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699739#M14106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've attached Demo.zip and the class A::TestClass::CVal is a constant declared in the header and defined in the CPP file and used in Main. DVal is declared and defined in the header and does not have the same issue as CVal.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Oct 2017 17:13:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699739#M14106</guid>
      <dc:creator>manishsangram</dc:creator>
      <dc:date>2017-10-10T17:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: C++ Constants going to SRAM</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699740#M14107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Zhang Jennie,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Were you able to look at the attached code and do you have any solution?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Oct 2017 18:48:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699740#M14107</guid>
      <dc:creator>manishsangram</dc:creator>
      <dc:date>2017-10-12T18:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: C++ Constants going to SRAM</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699741#M14108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Manish，&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Constant value must be assigned while it is declared.&amp;nbsp; Thus we can guarantee the constant value allocated in FLASH.&lt;/P&gt;&lt;P&gt;for example, the first time we define constant variable &lt;SPAN&gt;ConstantVal in *.h&lt;/SPAN&gt;, we need also assigned constant value to it&lt;/P&gt;&lt;P&gt;static const unsigned char &lt;SPAN&gt;ConstantVal;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;change to &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;static const unsigned char &lt;SPAN&gt;ConstantVal = 100;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;thus ConstantVal&amp;nbsp; is 0xaa, it can not be assigned to other value anymore.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;This is the same for C code.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Jennie Zhang&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Oct 2017 05:10:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/C-Constants-going-to-SRAM/m-p/699741#M14108</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2017-10-18T05:10:09Z</dc:date>
    </item>
  </channel>
</rss>

