<?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>topic Re: Compiler question: doesn't call global instance constructor in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156870#M2442</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;A href="https://community.nxp.com/people/eGuy"&gt;eGuy&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I want to use Cppunit in CodeWarrior too, but I couldn't add it to my project.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;In fact I added it to path and CodeWarrior can find header files, but for building the project I am getting so many error messages like:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;=#include &amp;lt;string&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt;the file 'string' cannot be opened&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(C:\cppunit\include\cppunit\TestCase.h|32|20|3|706|3)&lt;/P&gt;&lt;P&gt;=&amp;nbsp;&amp;nbsp;&amp;nbsp; TestCase( const std::string &amp;amp;name ); &lt;/P&gt;&lt;P&gt;&amp;gt;declaration syntax error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can I ask you how did you use CppUnit in your project?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Mar 2013 15:04:40 GMT</pubDate>
    <dc:creator>same</dc:creator>
    <dc:date>2013-03-08T15:04:40Z</dc:date>
    <item>
      <title>Compiler question: doesn't call global instance constructor</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156865#M2437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using&amp;nbsp; Codewarrior development studi for ColdFire V7.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The test code I have like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------&lt;/P&gt;&lt;P&gt;class testGroupStackTest&lt;BR /&gt;{ public:&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testGroupStackTest ()&amp;nbsp;&amp;nbsp; &amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; dummy =123;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int getdummy()&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; return dummy;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int dummy;&lt;BR /&gt;&amp;nbsp;};&lt;BR /&gt;&lt;BR /&gt;testGroupStackTest testGroupStackInstance;&lt;BR /&gt;&lt;BR /&gt;/* Task IDs */&lt;BR /&gt;#define HELLO_TASK 5&lt;BR /&gt;&lt;BR /&gt;extern void hello_task(uint_32);&lt;BR /&gt;&lt;BR /&gt;extern "C" const TASK_TEMPLATE_STRUCT&amp;nbsp; MQX_template_list[] =&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; /* Task Index,&amp;nbsp;&amp;nbsp; Function,&amp;nbsp;&amp;nbsp; Stack,&amp;nbsp; Priority, Name,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Attributes,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Param, Time Slice */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { HELLO_TASK,&amp;nbsp;&amp;nbsp; hello_task, 1500,&amp;nbsp;&amp;nbsp; 5,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "hello",&amp;nbsp; MQX_AUTO_START_TASK, 0,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 },&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { 0 }&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void hello_task&lt;BR /&gt;&amp;nbsp;&amp;nbsp; (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint_32 initial_data&lt;BR /&gt;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;{&lt;BR /&gt;int i;&lt;BR /&gt;//testGroupStackTest testGroupStackInstance;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; printf("\n Hello World \n");&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; i=testGroupStackInstance.getdummy();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; printf("dummy=%d\n",i);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; printf("\n Tests Done \n");&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; _mqx_exit(0);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I define testGroupStackInstance as Global instance, the constructor is never got called, the i value I get is Zero. however if I define testGroupStackInstance inside the task, I can get the correct i value dummy =123. What I am missing here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is great appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;J.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2009 22:34:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156865#M2437</guid>
      <dc:creator>eGuy</dc:creator>
      <dc:date>2009-11-24T22:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler question: doesn't call global instance constructor</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156866#M2438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The most likely cause is that you choosed to have a quick, non ISO-compliant startup code when you created the project.&lt;BR /&gt;&lt;BR /&gt;At project creation you can choose to use static initialization or not. Static initialization means that all statically allocated variables (static, globals etc) are initialized at startup, as required by ISO C / ISO C++. It also means that C++ constructors for statically allocated C++ objects will have their constructors called.&lt;BR /&gt;&lt;BR /&gt;In embedded systems, you typically want to avoid static initalization and init every variable in runtime instead, and call constructors in runtime instead. The C/C++ standards were designed for RAM-based desktop/telecom applications where the code doesn't sit in NVM at startup. Therefore C/C++ has requirements such as "all static variables must be zero before the program is started". In a NVM system such requirements are burdensome, as they mean you must run a lot of "copy-down" procedures before the system is started.&lt;BR /&gt;&lt;BR /&gt;To avoid this copy-down mess in embedded systems, you write the programs in such a way that they don't rely on static initialization. Ie instead of writing:&lt;BR /&gt;&lt;BR /&gt;int x = 5;&lt;BR /&gt;&lt;BR /&gt;you write&lt;BR /&gt;&lt;BR /&gt;int x;&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;void init_function()&lt;BR /&gt;{&lt;BR /&gt;x = 5;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;The very same applies to C++ constructors, you should call them in runtime and not at startup time.&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Lundin on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-24&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;04:16 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2009 23:15:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156866#M2438</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-11-24T23:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler question: doesn't call global instance constructor</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156867#M2439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you did create your project from a stationery, did you specify you want to use C++?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you are using global classes, you need a startup code, where the function __call_static_initializers is called. Additionally you need to make sure you link against Cpp run time library (Cpp_4i_CF_Runtime.a for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All these settings are set up appropriately if you let the project wizard know you intend to use C++ source file in your application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CrasyCat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2009 23:25:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156867#M2439</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2009-11-24T23:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler question: doesn't call global instance constructor</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156868#M2440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lundin &amp;amp; CrasyCat,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank both of you for your quick response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't created the project from scatch/stationery. I modified some example code ( in C ) from MQX's example. I added CPP_4i_CF_RegABI_Runtime.a and C++_4i_CF_RegABI_MSL.a manually to the project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way that I can specify I want to use C++ in the project setting page? (I tried "Force C++ compilation on C/C++ language page, it doesn't work)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to start project from a stationery&amp;nbsp; later today.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lundin, I am trying to use CppUnitLite in my project, that CppUnit registration machnism macros require global object instantiation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Nov 2009 23:44:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156868#M2440</guid>
      <dc:creator>eGuy</dc:creator>
      <dc:date>2009-11-24T23:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler question: doesn't call global instance constructor</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156869#M2441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Problem found:&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MQX overrides C++ initialization code in cw.c, see below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;cw.c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Override C++ inititialization so it happens later in _bsp_enable_card */&lt;BR /&gt;void __call_static_initializers(void){}&lt;BR /&gt;#pragma overload void __call_static_initializers(void);&lt;BR /&gt;------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We need to enable&amp;nbsp; BSPCFG_ENABLE_CPP in the configuration, so later the in _bsp_enable_card(), MQX will do the C++ constructor initialization, see below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------&lt;/P&gt;&lt;P&gt;init_bsp.c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _bsp_enable_card&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#if BSPCFG_ENABLE_CPP&lt;BR /&gt;&amp;nbsp;&amp;nbsp; /* initialize C++ constructors */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; __cpp_init();&lt;BR /&gt;#endif&lt;BR /&gt;&amp;nbsp;--------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy Thanksgivings&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;J.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2009 04:37:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156869#M2441</guid>
      <dc:creator>eGuy</dc:creator>
      <dc:date>2009-11-25T04:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler question: doesn't call global instance constructor</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156870#M2442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;A href="https://community.nxp.com/people/eGuy"&gt;eGuy&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I want to use Cppunit in CodeWarrior too, but I couldn't add it to my project.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;In fact I added it to path and CodeWarrior can find header files, but for building the project I am getting so many error messages like:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;=#include &amp;lt;string&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt;the file 'string' cannot be opened&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(C:\cppunit\include\cppunit\TestCase.h|32|20|3|706|3)&lt;/P&gt;&lt;P&gt;=&amp;nbsp;&amp;nbsp;&amp;nbsp; TestCase( const std::string &amp;amp;name ); &lt;/P&gt;&lt;P&gt;&amp;gt;declaration syntax error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can I ask you how did you use CppUnit in your project?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Mar 2013 15:04:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Compiler-question-doesn-t-call-global-instance-constructor/m-p/156870#M2442</guid>
      <dc:creator>same</dc:creator>
      <dc:date>2013-03-08T15:04:40Z</dc:date>
    </item>
  </channel>
</rss>

