<?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 Problem with sizeof() when using external arrays. in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problem-with-sizeof-when-using-external-arrays/m-p/847171#M14896</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it something I totally misunderstand. To figure out the size of a const char array I use sizeof(array)-1. Works fine when array is defined in the file where sizeof is used but when used as a external in a header file I get an error. Ide/compiler is Codewarrior version 11.0. I attached the project with the error.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Per Højfeldt&lt;/P&gt;&lt;P&gt;Without error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/76267i27E2E53A56A83808/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;With error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/76012i23E163E1B9B5A22C/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Nov 2018 15:13:14 GMT</pubDate>
    <dc:creator>perhojfeldt</dc:creator>
    <dc:date>2018-11-16T15:13:14Z</dc:date>
    <item>
      <title>Problem with sizeof() when using external arrays.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problem-with-sizeof-when-using-external-arrays/m-p/847171#M14896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it something I totally misunderstand. To figure out the size of a const char array I use sizeof(array)-1. Works fine when array is defined in the file where sizeof is used but when used as a external in a header file I get an error. Ide/compiler is Codewarrior version 11.0. I attached the project with the error.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Per Højfeldt&lt;/P&gt;&lt;P&gt;Without error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/76267i27E2E53A56A83808/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;With error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/76012i23E163E1B9B5A22C/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Nov 2018 15:13:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problem-with-sizeof-when-using-external-arrays/m-p/847171#M14896</guid>
      <dc:creator>perhojfeldt</dc:creator>
      <dc:date>2018-11-16T15:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with sizeof() when using external arrays.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problem-with-sizeof-when-using-external-arrays/m-p/847172#M14897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I figured out the problem. Use of sizeof() can not be used with an external because the compiler at compile time do not know the size of an external array. Correct me if I'm wrong. Make sense. The solution to the problem is to make a function with sizeof() where the array is defined and then make the function an external. That should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Example that can be declared external.&lt;/P&gt;&lt;P&gt;signed char const caArray[] = "1234";&lt;/P&gt;&lt;P&gt;unsigned char arrsize(void)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return sizeof(caArray)-1;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Per Højfeldt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Nov 2018 16:57:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problem-with-sizeof-when-using-external-arrays/m-p/847172#M14897</guid>
      <dc:creator>perhojfeldt</dc:creator>
      <dc:date>2018-11-16T16:57:52Z</dc:date>
    </item>
  </channel>
</rss>

