<?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: Casting function parameters C / C++ in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149277#M3507</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;I spent a good time trying to cast it by several ways....&lt;/P&gt;&lt;P&gt;Can we ask Freescale to add it to CW?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very thanks for your help..&lt;/P&gt;&lt;P&gt;Ricardo Raupp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Oct 2009 22:34:57 GMT</pubDate>
    <dc:creator>Ricardo_RauppV</dc:creator>
    <dc:date>2009-10-27T22:34:57Z</dc:date>
    <item>
      <title>Casting function parameters C / C++</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149275#M3505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hy guys&lt;/P&gt;&lt;P&gt;I´m using&amp;nbsp; CW6.2 C++ in a QE128 design, wich is about my post here...&lt;/P&gt;&lt;P&gt;I also use CW 7.1 for ColdFires.&lt;/P&gt;&lt;P&gt;In ColdFires IDE I can cast a parameter in order it matches the expected struct, without the need of build such struct to pass it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- THE STRUCT&amp;nbsp;&lt;/P&gt;&lt;P&gt;struct rtc_t&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uint8 day,month,year;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- THE FUNCTION&lt;/P&gt;&lt;P&gt;void cpu_rtc::write_rtc( rtc_t data )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rtc_cpu.day=data.day;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rtc_cpu.month=data.month;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; rtc_cpu.year=data.year;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- THE CALLING&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;This works:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtc_t r={1,2,3};// init var rtc_t type&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; write_rtc( r);&amp;nbsp; //&amp;nbsp;pass expected type to the function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;This ( the way I want ) doesn´t work: CW complains about wrong cast.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write_rtc( (rtc_t) {26,10,9});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works in CW7.1 for ColdFires ( pure C ...I didn´t try C++ yet)&lt;/P&gt;&lt;P&gt;Its very practical, once we don´t need to formally&amp;nbsp;create a struct to use as parameter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could not make it work in CW6.2 using C++ (maybe it dodesn´t work even in C.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did I forget some small detail to accomplish it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone some experience like that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everybody !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ricardo Raupp&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Oct 2009 00:06:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149275#M3505</guid>
      <dc:creator>Ricardo_RauppV</dc:creator>
      <dc:date>2009-10-27T00:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Casting function parameters C / C++</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149276#M3506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's a C99 feature called compound literals. The HC08 compiler does not support this C99 extension while the CF compiler does support it.&lt;/P&gt;&lt;P&gt;For now you will have to create local structs or pass the individual members separately into the function.&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>Tue, 27 Oct 2009 10:41:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149276#M3506</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2009-10-27T10:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Casting function parameters C / C++</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149277#M3507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;I spent a good time trying to cast it by several ways....&lt;/P&gt;&lt;P&gt;Can we ask Freescale to add it to CW?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very thanks for your help..&lt;/P&gt;&lt;P&gt;Ricardo Raupp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Oct 2009 22:34:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149277#M3507</guid>
      <dc:creator>Ricardo_RauppV</dc:creator>
      <dc:date>2009-10-27T22:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Casting function parameters C / C++</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149278#M3508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;That code isn't "pure C", but as mentioned it is C99, which is a standard that hasn't received a wider acceptance in the industry. The industry de facto standard is still "C90" (ISO 9899:1990).&lt;BR /&gt;&lt;BR /&gt;Therefore you probably don't want to use C99 in embedded apps, because of portability reasons. There are very few compilers supporting it. Sticking to C++ might be better if you are unsure of the difference between C90 and C99.&lt;BR /&gt;&lt;BR /&gt;Also, as a rule of thumb you should never pass structs by value. It turns the code inefficient for no reason. You might think there are only a few bytes passed, but the compiler is free to add additional padding bytes to a struct/union. This is especially poor practice on microcontrollers with limited RAM and stack space.&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Oct 2009 03:15:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Casting-function-parameters-C-C/m-p/149278#M3508</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-10-28T03:15:09Z</dc:date>
    </item>
  </channel>
</rss>

