<?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>LPCXpresso IDE中的主题 Re: Optimization issue?</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Optimization-issue/m-p/529105#M1302</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by fancypants on Wed Feb 06 23:27:44 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Following up on this issue: it seems to be fixed in v5.1.0. I don't know what the root issue was but it appears to be working as expected in this release.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-K&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 21:41:38 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T21:41:38Z</dc:date>
    <item>
      <title>Optimization issue?</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Optimization-issue/m-p/529104#M1301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by fancypants on Fri Feb 01 19:40:15 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm getting an operational difference between the debug and release build. I haven't been able to track down if it is me or the compiler. I'm hoping someone can shed some light.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've created "templatizing" macros for things like queue management. The macros create unique functions depending on the datatype needed. For example, if a queue of uint32_t type needs to be managed, the macros create unique functions for that type. It can even be custom struct type.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The debug build accesses the queue elements properly. The release build does not access the queue elements properly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/* "templatizing macros */
#define DEFINE_QUEUE_FUNCTIONS(elem_type)\
void QueueInit_##elem_type##_(tQueue *pQ, elem_type array[], size_t num_elems) {\
pQ-&amp;gt;pData = array;\
pQ-&amp;gt;ElementsIn = num_elems - 1;\
pQ-&amp;gt;iHead = pQ-&amp;gt;iTail = 0;\
}\
elem_type QueueRemoveElement_##elem_type##_(tQueue *pQ) {\
elem_type elem;\
elem = ((elem_type*)(pQ-&amp;gt;pData))[pQ-&amp;gt;iTail];\
pQ-&amp;gt;iTail = (pQ-&amp;gt;iTail + 1) % pQ-&amp;gt;ElementsIn;\
return(elem);\
}\
void QueueAddElement_##elem_type##_(tQueue *pQ, elem_type elem) {\
((elem_type*)(pQ-&amp;gt;pData))[pQ-&amp;gt;iHead] = elem;\
pQ-&amp;gt;iHead = (pQ-&amp;gt;iHead + 1) % pQ-&amp;gt;ElementsIn;\
}

/* generic queue macro accessor function */
/* init a queue instance */
#define QueueInit(elem_type, t_queue_ptr, elem_array_ptr, num_elems)\
QueueInit_##elem_type##_(t_queue_ptr, elem_array_ptr, num_elems)
/* remove an element from the queue instance */
#define QueueRemoveElement(elem_type, t_queue_ptr)\
QueueRemoveElement_##elem_type##_(t_queue_ptr)
/* add an element to the queue instance */
#define QueueAddElement(elem_type, t_queue_ptr, elem)\
QueueAddElement_##elem_type##_(t_queue_ptr, elem)

/* queue manager struct */
typedef struct {
void&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *pData;
size_tElementsIn;
size_tiHead;
size_tiTail;
} tQueue;

/* custom data type struct */
typedef struct {
uint8_tData;
uint8_tTag;
} tCustomData;

/* creates the unique functions that operate on tCustomData types */
DEFINE_QUEUE_FUNCTIONS(tCustomData);

/* code */
tCustomData _CustomData;
main()
{
tQueue QCustomData;
tCustomData aCustomData[5];
uint32_t i;

QueueInit(tCustomData, &amp;amp;QCustomData, aCustomData, (sizeof(aCustomData)/sizeof(aCustomData[0])));
for(i = 0; i &amp;lt; (sizeof(aCustomData)/sizeof(aCustomData[0])) - 1; i++)
{
_CustomData.Data = i;
_CustomData.Tag = i;
QueueAddElement(tCustomData, &amp;amp;QCustomData, _CustomData);
}
for(i = 0; i &amp;lt; (sizeof(aCustomData)/sizeof(aCustomData[0])) - 1; i++)
{
_CustomData = QueueRemoveElement(tCustomData, &amp;amp;QCustomData); /* &amp;lt;&amp;lt;&amp;lt; the returned data is correct in "debug"; incorrect in "release" */
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm assuming the tCustomData type should be size equivalent to uint16_t; If I add support and modify the code for uint16_t, it works as expected in both "debug" and "release":&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
DEFINE_QUEUE_FUNCTIONS(uint16_t);
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I always assume it is my fault, so I'll assume so here too, I just can't find what I'm doing wrong, so I'm hoping someone has some insight.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using Mac v5.0.14 (build 1063).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;TIA.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-K&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:41:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Optimization-issue/m-p/529104#M1301</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Optimization issue?</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Optimization-issue/m-p/529105#M1302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by fancypants on Wed Feb 06 23:27:44 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Following up on this issue: it seems to be fixed in v5.1.0. I don't know what the root issue was but it appears to be working as expected in this release.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-K&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:41:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Optimization-issue/m-p/529105#M1302</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:41:38Z</dc:date>
    </item>
  </channel>
</rss>

