<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Const data changes during program execution</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29599/const-data-changes-during-program-execution</link><description> 
hi, 

 
(lpc1317-64P) 
during execution of my code const data changes. I don&amp;#39;t know how. 
I have used 
const uint8_t *p[] = { &amp;quot;&amp;quot;, &amp;quot;abcd&amp;quot;, }; 

 
I have checked by adding the array in watch. At one point randomly
data in null type gets changed to some</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Const data changes during program execution</title><link>https://community.arm.com/thread/80947?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2013 15:48:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e08cf799-e544-4b1d-b508-360fae491561</guid><dc:creator>c decl</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;This is an array of two const pointers to uint8_t.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Umm no, but this is:&lt;/p&gt;

&lt;pre&gt;
uint8_t * const p[];
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Const data changes during program execution</title><link>https://community.arm.com/thread/61616?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2013 14:05:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b343a094-705b-4c99-b225-df1b6b063472</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;pre&gt;
&lt;i&gt;const uint8_t *p[] = { &amp;quot;&amp;quot;, &amp;quot;abcd&amp;quot;, };&lt;/i&gt;
&lt;/pre&gt;

&lt;p&gt;
That is not quite as const as you may think it is. This is an
array of two const pointers to uint8_t. Note that this means the
uint8_t data themselves are &lt;b&gt;not&lt;/b&gt; const.&lt;/p&gt;

&lt;p&gt;
And another thing: it is easy to make the mistake of believing
that &amp;#39;const&amp;#39; qualified data are 100% totally unmodifiable, read-only
data. That&amp;#39;s not the case. &amp;#39;const&amp;#39; only means that an otherwise
correct C program will not be able to write to them. There&amp;#39;s a
difference.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Const data changes during program execution</title><link>https://community.arm.com/thread/92956?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2013 04:17:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5ab0eac1-8990-4722-bf00-ccc69c305641</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Various other things could also cause the change:&lt;/p&gt;

&lt;p&gt;
Being accessed by a pointer (deliberately or otherwise) that
doesn&amp;#39;t have a &amp;#39;const&amp;#39; qualifier;&lt;/p&gt;

&lt;p&gt;
Stack overflow;&lt;/p&gt;

&lt;p&gt;
Buffer over/under-run;&lt;/p&gt;

&lt;p&gt;
DMA;&lt;/p&gt;

&lt;p&gt;
probably others...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Const data changes during program execution</title><link>https://community.arm.com/thread/61617?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2013 03:54:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:82e449c9-32e7-4aed-b235-fe4225207c5a</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I have checked by adding the array in watch&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
There is a difference in the behaviour of the &amp;#39;abstract machine&amp;#39;
and the &amp;#39;real machine&amp;#39; that you see in the watch window. One major
reason is compiler optimizations that limit lifetime of variables.
Also, the compiler may generate incomplete or incorrect debugging
information. Besides, the debugger may interpret debugging
information incorrectly. Of course, those would be bugs in the
compiler or the debugger. Such bugs are considered non-critical since
they don&amp;#39;t affect the correctness of generated machine code.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;However const data shouldn&amp;#39;t be changed&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I have a surprise for you: if you declare a &lt;b&gt;const&lt;/b&gt; variable
at function scope with no &lt;b&gt;static&lt;/b&gt; keyword (that is, the
variable is automatic) then the variable will be allocated on the
stack. It is easy to change the contents of such variable through a
pointer.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>