<?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 #define issues in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198683#M5271</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've run into the following problem with using calculated defines with the compiler.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These three defined in a bean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//#define DATA_FLASH_SECTOR_SIZE 256u&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//#define DATA_FLASH_END&amp;nbsp;&amp;nbsp; 8191&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//#define DATA_FLASH_START 4096&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These were my defines:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define NVRAM_SECTORS_RESERVE&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define MAX_SECTORS&amp;nbsp;&amp;nbsp;&amp;nbsp; ((DATA_FLASH_END +1 - DATA_FLASH_START)/DATA_FLASH_SECTOR_SIZE) - NVRAM_SECTORS_RESERVE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define BLK_SIZE 16&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define MAX_BLKS&amp;nbsp; (MAX_SECTORS * (DATA_FLASH_SECTOR_SIZE / BLK_SIZE))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;MAX_SECTORS calculated correctly to 12 but MAX_BLKS calculated to some number about 65k when it should be 192.&amp;nbsp; I've had to enter it's value literally to make it work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a mistake here or is the compiler not able to handle the sequential number of calculations required to get to the value requested?&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm concerned if there is some limitation I need to know about.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&amp;nbsp; Bob&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Oct 2008 20:55:53 GMT</pubDate>
    <dc:creator>bob_s</dc:creator>
    <dc:date>2008-10-31T20:55:53Z</dc:date>
    <item>
      <title>#define issues</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198683#M5271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've run into the following problem with using calculated defines with the compiler.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These three defined in a bean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//#define DATA_FLASH_SECTOR_SIZE 256u&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//#define DATA_FLASH_END&amp;nbsp;&amp;nbsp; 8191&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//#define DATA_FLASH_START 4096&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These were my defines:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define NVRAM_SECTORS_RESERVE&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define MAX_SECTORS&amp;nbsp;&amp;nbsp;&amp;nbsp; ((DATA_FLASH_END +1 - DATA_FLASH_START)/DATA_FLASH_SECTOR_SIZE) - NVRAM_SECTORS_RESERVE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define BLK_SIZE 16&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define MAX_BLKS&amp;nbsp; (MAX_SECTORS * (DATA_FLASH_SECTOR_SIZE / BLK_SIZE))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;MAX_SECTORS calculated correctly to 12 but MAX_BLKS calculated to some number about 65k when it should be 192.&amp;nbsp; I've had to enter it's value literally to make it work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a mistake here or is the compiler not able to handle the sequential number of calculations required to get to the value requested?&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm concerned if there is some limitation I need to know about.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&amp;nbsp; Bob&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 20:55:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198683#M5271</guid>
      <dc:creator>bob_s</dc:creator>
      <dc:date>2008-10-31T20:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: #define issues</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198684#M5272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;There is a pair of parentheses missing in the &lt;B&gt;&lt;/B&gt;MAX_SECTORS macro.&lt;BR /&gt;As it is, the&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#define MAX_BLKS  (MAX_SECTORS * (DATA_FLASH_SECTOR_SIZE / BLK_SIZE))&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;macro expands to&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#define MAX_BLKS  (((DATA_FLASH_END +1 - DATA_FLASH_START)/DATA_FLASH_SECTOR_SIZE) - NVRAM_SECTORS_RESERVE * (DATA_FLASH_SECTOR_SIZE / BLK_SIZE))&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;so only NVRAM_SECTORS_RESERVE gets multiplied and not the value of NVRAM_SECTORS_RESERVE.&lt;BR /&gt;&lt;BR /&gt;In general in C all but the most simple macros should start with a opening paranthesis and close with a closing one. In addition for macros with arguments, the argument should be enclosed in parentheses too.&lt;BR /&gt;&lt;BR /&gt;So MAX_SECTORS should be defined as:&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#define MAX_SECTORS (((DATA_FLASH_END +1 - DATA_FLASH_START)/DATA_FLASH_SECTOR_SIZE) - NVRAM_SECTORS_RESERVE)&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;As additional tip, if anything looks wrong with macros, always check the preprocessor output.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 21:22:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198684#M5272</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-10-31T21:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: #define issues</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198685#M5273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks Daniel for your response.&lt;BR /&gt;&lt;BR /&gt;I see why the additional parenthesis needed to be added to 'MAX_SECTORS'.&lt;BR /&gt;&lt;BR /&gt;I looked through the preprocessor file for the 'MAX_BLKS' value, but I did not see it.&lt;BR /&gt;&lt;BR /&gt;Bob&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 22:02:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198685#M5273</guid>
      <dc:creator>bob_s</dc:creator>
      <dc:date>2008-10-31T22:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: #define issues</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198686#M5274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I found that the preprocessor sends a formula rather than the result which I found in the preprocess of the code rather than the header file.&amp;nbsp; That helps.&amp;nbsp; Thanks Daniel.&amp;nbsp; Bob&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2008 22:37:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/define-issues/m-p/198686#M5274</guid>
      <dc:creator>bob_s</dc:creator>
      <dc:date>2008-10-31T22:37:51Z</dc:date>
    </item>
  </channel>
</rss>

