<?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>Return from a function is not stable! - C51</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/21277/return-from-a-function-is-not-stable---c51</link><description> 
Dear All, 

 
In the below program, main function calls &amp;quot;yaz&amp;quot; function 10 times.
it works fine without any problem with the global variable definition
marked as &amp;quot; bold &amp;quot; &amp;quot;unsigned char i&amp;quot; altough it is not used in
the program. When I ignore or delete</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/98985?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2007 02:25:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ff115951-c351-40d6-8556-d01aa0b99e27</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;this is my mistake to put 9 for &amp;#39;row&amp;#39;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
This is why so-called &amp;quot;magic numbers&amp;quot; are a bad thing!&lt;/p&gt;

&lt;p&gt;
Rather than use a literal number, it would be far safer to use
some symbolic constant (eg, #define or enum) so that it will
&lt;i&gt;&lt;b&gt;automatically&lt;/b&gt;&lt;/i&gt; be right&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/74891?ContentTypeID=1</link><pubDate>Sun, 04 Mar 2007 09:05:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:434a65f5-adad-4f8a-ac00-0bce7671d375</guid><dc:creator>Akif Kutlu</dc:creator><description>&lt;p&gt;&lt;p&gt;
You are absolutely right.. :-) this is my mistake to put 9 for
&amp;quot;row&amp;quot; ..&lt;/p&gt;

&lt;p&gt;
Thanks.&lt;br /&gt;
akif&lt;/p&gt;

&lt;pre&gt;
        for (k=1; k&amp;lt;=8; k++) {
                for (row=0;row&amp;lt;&lt;b&gt;8&lt;/b&gt;;row++)       {
                        sdeger=gonder[row];
                        sdeger=sdeger&amp;lt;&amp;lt;n;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/123710?ContentTypeID=1</link><pubDate>Sun, 04 Mar 2007 07:35:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8a79c355-e26c-4be9-a174-a372cd7ebf66</guid><dc:creator>Akif Kutlu</dc:creator><description>&lt;p&gt;&lt;p&gt;
I agree that it is a kind of corruption on the data area with
stack or something else.&lt;br /&gt;
If I change the first line definition from:&lt;br /&gt;
unsigned char data gdeger[8]; to &amp;quot;unsigned char &lt;b&gt;xdata&lt;/b&gt;
gdeger[8]; &amp;quot;yaz&amp;quot; function returns to main() and program starts
working as i expected.&lt;/p&gt;

&lt;p&gt;
I am also doing some work to sort it out what &amp;quot;Dan hanry&amp;quot;
says.&lt;br /&gt;
Thanks to all.&lt;br /&gt;
akif&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/112712?ContentTypeID=1</link><pubDate>Sat, 03 Mar 2007 16:46:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:26910d4d-3cc5-4e22-82ce-044fe55b726e</guid><dc:creator>Dan Henry</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;... something more important breaks up.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
And if the OP were to look at the link map and see that (assuming
small model) the stack is immediately after gdeger[], that
&lt;i&gt;something&lt;/i&gt; is quite likely part of a return address.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/112706?ContentTypeID=1</link><pubDate>Sat, 03 Mar 2007 16:43:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:36fd0c05-0a3a-4c2e-bed6-04c4b40619e3</guid><dc:creator>Jonny Doin</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;something more important breaks up&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Since you are declaring your array in &lt;b&gt;data&lt;/b&gt; memory, probably
it is the return stack that is getting corrupted.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/98988?ContentTypeID=1</link><pubDate>Sat, 03 Mar 2007 16:41:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:433d35ce-0492-489e-a6a4-23d6911c590b</guid><dc:creator>Jonny Doin</dc:creator><description>&lt;p&gt;&lt;p&gt;
As Dan said, you are reading past rakam[s][7] and writing past
gdeger[7]. The compiler will happily overwrite your memory and with
some luck crash and burn.&lt;/p&gt;

&lt;p&gt;
When you declare your unused global variable, it is probably being
the one that is overwritten. When you comment it out, something more
important breaks up.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/88212?ContentTypeID=1</link><pubDate>Sat, 03 Mar 2007 16:14:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9abff5ae-33b3-4637-b4cf-771507af8ddf</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;&lt;p&gt;
What happens when you run this source through PC-Lint?&lt;/p&gt;

&lt;p&gt;
&lt;a href="http://www.gimpel.com/"&gt;http://www.gimpel.com/&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Return from a function is not stable! - C51</title><link>https://community.arm.com/thread/47910?ContentTypeID=1</link><pubDate>Sat, 03 Mar 2007 14:41:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5268560f-9045-4faf-9476-1fc2a53f6bd3</guid><dc:creator>Dan Henry</dc:creator><description>&lt;p&gt;&lt;p&gt;
What happens when row is 8 and attempts to access the nonexistent
9th element of 8-element arrays?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>