<?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: constant structure on 9S12 in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385289#M6799</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got feedback from compiler team.&lt;/P&gt;&lt;P&gt;See below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+++++++++++++++++++&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt;The value of &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'Courier New';"&gt;OUTBACK_SOURCE_VOLTAGE_NDX&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt; might be evaluated as a constant at compile time (even if its components do not have the correct / expected content).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt;This is just a guess, we cannot state from the provided description that this is the case (maybe the code with the complete definition of &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'Courier New';"&gt;OUTBACK_SOURCE_VOLTAGE_NDX&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt; and of its components might help).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt;If this is the case (and the &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'Courier New';"&gt;OUTBACK_SOURCE_VOLTAGE_NDX&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt; can be evaluated as a constant), the compiler does not report any issue (even if the constant evaluated at compile time does not contain the expected value).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;+++++++++++++++++++&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Pascal&lt;BR /&gt;Freescale Technical Support&lt;BR /&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>Fri, 06 Mar 2015 10:10:07 GMT</pubDate>
    <dc:creator>trytohelp</dc:creator>
    <dc:date>2015-03-06T10:10:07Z</dc:date>
    <item>
      <title>constant structure on 9S12</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385287#M6797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found an incorrect index was generated in an constant array of structures.&amp;nbsp; I'm curious if it's possible to get the compiler to flag this as a warning or error.&lt;/P&gt;&lt;P&gt;The project creates an array of structures that represent CANOpen Object Dictionary entries.&amp;nbsp; Here are the typedefs.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style=""&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;typedef union _DICT_PTRS {&amp;nbsp; &lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style=""&gt;&lt;/TD&gt;&lt;TD style=""&gt;&lt;/TD&gt;&lt;TD style=""&gt;&lt;/TD&gt;&lt;TD style=""&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt; /* Pointers to objects */&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; long EEAdr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const unsigned char * pRom;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char * pRam;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (* pFunc)(PCHAR pDict);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;} DICT_PTRS;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;typedef struct _DICTIONARY_OBJECT_TEMPLATE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int index;&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;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char subindex;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BYTE ctl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int len;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DICT_PTRS p;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;}DICT_OBJECT_TEMPLATE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next the array definition.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;const DICT_OBJECT_TEMPLATE manufacturer[] = {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0x3000,0x00,CONST,1,(long)&amp;amp;UserDictionaryLen},&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0x3000,0x01,RO,2,(long)&amp;amp;ObjectDictionary[BIM_INPUTS_NDX]},&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0x3000,0x02,RO,2,(long)&amp;amp;ObjectDictionary[SMU_INPUTS_NDX]},&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0x3000,0x03,RO,2,(long)&amp;amp;ObjectDictionary[GIM_INPUTS_NDX]},&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0x3000,0x04,RO,2,(long)&amp;amp;ModBusRegisters[OUTBACK_SOURCE_VOLTAGE_NDX]},&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, there's nothing wrong with the code as is.&amp;nbsp; It's possible to use the functions that work with the array to return the values.&amp;nbsp; In each case the constants that end with NDX are simple #defines that are eventually integers.&amp;nbsp; Looking at the code with the debugger the pointers to the data are correct.&amp;nbsp; Except for the ModBusRegsters[&lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;OUTBACK_SOURCE_VOLTAGE_NDX]&lt;SPAN style="font-size: 10pt; font-family: calibri,verdana,arial,sans-serif;"&gt; &lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;which is 0.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;The problem is that OUTBACK_SOURCE_VOLTAGE_NDX isn't an integer but is (adrChargeControllerBlk+9) and &lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;adrChargeControllerBlk is a variable filled in from a MODBUS messages identifying the location of the source voltage value.&amp;nbsp; So the index into the Modbus Registers is dynamic and normally has the value 362..&amp;nbsp; That doesn't work in a constant array because at compile time the contents of &lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;adrChargeControllerBlk are unknown. &lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;In the function that receives the Modbus values it's easy enough to assign the value into a global variable and then use this array entry instead.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style=""&gt;&lt;/TD&gt;&lt;TD style=""&gt;{0x3000,0x33,RO,2,(long)&amp;amp;SolarInputVoltage},&lt;/TD&gt;&lt;TD style=""&gt;// Filled in if MODBUS active&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;Now the constant array has a pointer to the variable SolarInputVoltage and accessing it via the 3000:04 CANOpen Index:Sub-Index returns the correct value.&amp;nbsp; A look with the debugger now shows the correct address in the data structure.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So using the contents of a variable to index a constant array is the problem.&amp;nbsp; The compiler generates a 0 instead of the actual location which it can't know because it doesn't know what's in the variable.&amp;nbsp; All perfectly logical.&amp;nbsp; But shouldn't the compiler complain?&amp;nbsp; I shouldn't have named the index an NDX type.&amp;nbsp; That fooled me into thinking it was an integer a year later when I started using it in this data structure.&amp;nbsp;&amp;nbsp; But still I'd expect an error or at least a warning.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Feb 2015 08:48:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385287#M6797</guid>
      <dc:creator>jcdammeyer</dc:creator>
      <dc:date>2015-02-19T08:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: constant structure on 9S12</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385288#M6798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For my understanding:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - the compiler can not check it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For the compile there is no error in the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The &lt;SPAN style="font-family: courier new,courier; font-size: 8pt;"&gt;OUTBACK_SOURCE_VOLTAGE_NDX &lt;/SPAN&gt;is defined in another module (outside the c file where the &lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;manufacturer is defined&lt;/SPAN&gt; ) the compiler can not check the address. the address is defined during the link operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - the linker doesn't check it too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The linker is checking memory location, overlap, not missing declarations (functions &amp;amp; variables), ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately I think this type of problem can not be detected by the build tool chain.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will contact the development team just to have their feedback about that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Pascal&lt;BR /&gt;Freescale Technical Support&lt;BR /&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, 25 Feb 2015 16:55:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385288#M6798</guid>
      <dc:creator>trytohelp</dc:creator>
      <dc:date>2015-02-25T16:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: constant structure on 9S12</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385289#M6799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got feedback from compiler team.&lt;/P&gt;&lt;P&gt;See below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+++++++++++++++++++&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt;The value of &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'Courier New';"&gt;OUTBACK_SOURCE_VOLTAGE_NDX&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt; might be evaluated as a constant at compile time (even if its components do not have the correct / expected content).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt;This is just a guess, we cannot state from the provided description that this is the case (maybe the code with the complete definition of &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'Courier New';"&gt;OUTBACK_SOURCE_VOLTAGE_NDX&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt; and of its components might help).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt;If this is the case (and the &lt;/SPAN&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'Courier New';"&gt;OUTBACK_SOURCE_VOLTAGE_NDX&lt;/SPAN&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif; color: #1f497d;"&gt; can be evaluated as a constant), the compiler does not report any issue (even if the constant evaluated at compile time does not contain the expected value).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;+++++++++++++++++++&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Pascal&lt;BR /&gt;Freescale Technical Support&lt;BR /&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>Fri, 06 Mar 2015 10:10:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/constant-structure-on-9S12/m-p/385289#M6799</guid>
      <dc:creator>trytohelp</dc:creator>
      <dc:date>2015-03-06T10:10:07Z</dc:date>
    </item>
  </channel>
</rss>

