<?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>how to realize exit(0) function in keilC51</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/26635/how-to-realize-exit-0-function-in-keilc51</link><description> 
HI: We can use exit(0) instruction to exit a normally running
routine in C language. But exit(0) is not being in the KEILC51.Now
how can I realize the same function as exit(0) instruction with other
instructions? 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/126307?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 23:22:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9545ad7d-4a32-40cb-8515-745fc0330fea</guid><dc:creator>you could do it</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;No, it&amp;#39;s not, because like with all functions defined by the
standard&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
It is a rule of a standard, it should not be confused with some
law of physics.&lt;/p&gt;

&lt;p&gt;
A sign saying &amp;quot;no entry&amp;quot; does not do anything to physically stop
someone driving up a road the wrong way.&lt;/p&gt;

&lt;pre&gt;

#define BEGIN }
#define END   {

void main(void)
END
   ;
BEGIN

&lt;/pre&gt;

&lt;p&gt;
Looks crazy, stupid etc, but you can still do it.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/115921?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 14:45:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ff502edc-0e3a-45cf-b4bf-084688c554cc</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;It is possible to realize the function exit(0).&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No, it&amp;#39;s not, because like with all functions defined by the
standard,&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;and decide what you want it to do.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
is not an option. The C Standard defines what exit() does. If
you&amp;#39;re going to implement a function that does something else, you
are for practical intents and purposes forbidden to call that
function exit().&lt;/p&gt;

&lt;p&gt;
And there&amp;#39;s quite exactly no way to fulfill the standard&amp;#39;s
requirement for exit() on an 8051, of all things. C on a &amp;#39;51 is,
pretty much necessarily, a free-standing implementation, as opposed
to a hosted one. As such, a C51 program is forbidden to call exit()
because &amp;lt;stdlib.h&amp;gt; is not among the headers listed in C99,
chapter 4, paragraph 6. And because there is no &amp;quot;host environment&amp;quot; to
return to.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/146577?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 12:08:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8d3963ea-426e-468c-a1c4-97013c521547</guid><dc:creator>you could do it</dc:creator><description>&lt;p&gt;&lt;p&gt;
Wherever you would like it to exit to.&lt;/p&gt;

&lt;p&gt;
&amp;quot;What&amp;#39;s in a name? That which we call a rose ...&amp;quot;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/144921?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 09:31:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:55cba39a-cf33-4cc5-9a2b-3cbc53f18336</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/142685?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 08:35:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:55a4729f-97bd-4c68-a80a-8f785059f141</guid><dc:creator>you could do it</dc:creator><description>&lt;p&gt;&lt;p&gt;
Of course you can; as I explained previously.&lt;/p&gt;

&lt;p&gt;
Use of the function name &lt;i&gt;exit&lt;/i&gt; may be misleading, but it
&lt;b&gt;can&lt;/b&gt; be done.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/142671?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 07:27:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bd0f2121-bcc9-4e42-a3d2-620e627c400f</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;We can NOT use exit(0) instruction to exit a normally running
routine in EMBEDDED C&amp;quot;&lt;/p&gt;

&lt;p&gt;
Yes we can. We just have to define ourselves what should happen.
It&amp;#39;s just that the most likely decisions would lead to a similar
function but with a very different name - something like:&lt;br /&gt;
halt()&lt;br /&gt;
shutdown()&lt;br /&gt;
reboot()&lt;br /&gt;
reset()&lt;br /&gt;
restart()&lt;br /&gt;
power_off()&lt;br /&gt;
power_cycle()&lt;br /&gt;
lock_up_until_manual_reset()&lt;br /&gt;
return_to_bootloader()&lt;/p&gt;

&lt;p&gt;
If we do have a boot loader, then a running program _can_ exit()
to another program that will pick up the execution. But since it
isn&amp;#39;t as obvious in an embedded device that there are anything that
may possibly pick up the pieces after an exit, and since a boot
loader may not be implemented so that it is entough to just run past
the last closing brace of main(), any jump to a boot loader will
normally have to be very explicit, giving a reason for a more
explicit name than just the generic exit().&lt;/p&gt;

&lt;p&gt;
So the concept of an exit() can be had. But a generic
implementation can&amp;#39;t exist without a minimalistic OS or application
laucher, and without an application launcher the meaning/result of
such a call is not obvious. Hence, the name exit() should not exist
in any device that does not have a generic application launcher.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/139645?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 07:05:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e3ad4211-785a-4a04-9182-f7f6bbf5d111</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/136217?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 06:18:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:236c2061-e1f8-4ba0-82f3-03b400623765</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think lots of embedded systems have methods to implement
different abort() solutions where a failure may be emitted to
flash/EEPROM/LEDs/UART/...&lt;/p&gt;

&lt;p&gt;
But then we are normally talking about an abort or shutdown or
forced reboot - not a normal &amp;quot;exit&amp;quot;. The function exit() is expected
to make a controlled exit - close open files etc. A problem when you
really do find such a bad problem that you need to abort the program
run, is how to know that you are enough in control that you may dare
to do the last touch-up of a flash file system before a restart? And
more interestingly - what should/could a compiler vendor do?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/126306?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 06:05:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e1e2bfb1-abb0-4415-9b0d-9315cddfa99d</guid><dc:creator>you could do it</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;But an embedded system has no need for any program return code
since the program will not return to something making use of
it.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
One possible reason to do it would be to give a reason for the
exit, store it to non-vol and then report it on the next
power-up.&lt;/p&gt;

&lt;p&gt;
Done a similar thing myself where the function could be called
from anywhere (including an ISR), and report the assertion fault on
the restart.&lt;/p&gt;

&lt;p&gt;
I&amp;#39;m not condoning the use of the name &lt;i&gt;exit&lt;/i&gt;, just giving an
alternate view.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/115920?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 05:42:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ff235c5c-9756-4194-965f-0d75a8423cbe</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Of course it is possible to implement an exit() function.&lt;/p&gt;

&lt;p&gt;
But an embedded system has no need for any program return code
since the program will not return to something making use of it.&lt;/p&gt;

&lt;p&gt;
So an exit() function would then probably have to either reboot
the system, or cut the power. But the individual developer must make
the decision exactly what exit(0) should do before making such an
implementation.&lt;/p&gt;

&lt;p&gt;
So if the end result is a function that reboots the hw target,
it&amp;#39;s better to call that function reboot(). And if the end result is
a function that cuts the power, it&amp;#39;s better to call that function
cut_power().&lt;/p&gt;

&lt;p&gt;
In the end, even if it is possible to implement a function with
the name exit() and that takes one integer parameter, it&amp;#39;s normally
better to not implement such a function since the meaning of the
function will not be the same as the exit() function known from any
standard.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/102244?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 05:11:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2057f9a1-8c1d-4e86-bc97-6b0a0e03321e</guid><dc:creator>you could do it</dc:creator><description>&lt;p&gt;&lt;p&gt;
It &lt;b&gt;is&lt;/b&gt; possible to &lt;i&gt;realize&lt;/i&gt; the function exit(0).&lt;/p&gt;

&lt;p&gt;
There&amp;#39;s nothing magical about the exit function per se.&lt;/p&gt;

&lt;p&gt;
All you need to do is (re)define the function yourself and decide
what you want it to do.&lt;/p&gt;

&lt;p&gt;
Easy.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/90536?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2010 04:54:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8e285445-bb1d-45c0-bd40-efb8234f266f</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
He has, of course, installed MS-DOS or Windows 95 on his embedded
device, so after executing exit(0), he will either get to a command
line prompt, or back to the graphical desktop, where the OS will wait
for the name and arguments of the next program to run.&lt;/p&gt;

&lt;p&gt;
The only way a embedded device can stopp running it&amp;#39;s program is
when the power is cut, unless the processor has a &amp;quot;halt&amp;quot; instruction.
But even a &amp;quot;halt&amp;quot; instruction normally means that the processor
supports some non-maskable interrupt or similar, in case there may be
a need to still have a loaded program containing such a interrupt
handler.&lt;/p&gt;

&lt;p&gt;
Since a embedded application can&amp;#39;t stop running any program, there
is about zero percent reasons to add a exit(0) function to the
runtime library. It is up to the develiper (you) to figure out a way
to cut the power to the device, or to have it sleep until next time
the user wakes it up again. That is hardware-specific code that can
not be supplied in the runtime library.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/65756?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2010 22:43:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fdf23d3a-98cb-4c2b-9503-7c6d86dedfd0</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
No, we can&amp;#39;t!&lt;/p&gt;

&lt;p&gt;
We can use exit(0) instruction to exit a normally running
&lt;i&gt;&lt;b&gt;program&lt;/b&gt;&lt;/i&gt; in C language!&lt;/p&gt;

&lt;p&gt;
How do you think that would be meaningful to any
&lt;b&gt;&lt;i&gt;embedded&lt;/i&gt; system&lt;/b&gt; in general, or an 8051 system in
particular...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to realize exit(0) function in keilC51</title><link>https://community.arm.com/thread/58477?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2010 20:58:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b03e8aea-d0f5-4a8e-9a40-35af6a3ed8c9</guid><dc:creator>Tamir Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sounds like the compiler is your best friend!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>