I know there are many functions that I can exit the program such as
return 0,
exit(0), exit(1),_EXIT(0) ....
What are the difference between them?
Thanks a lot! 5 28004
QQ <ju****@yahoo.com> scribbled the following: I know there are many functions that I can exit the program such as return 0, exit(0), exit(1),_EXIT(0) ....
What are the difference between them?
Thanks a lot!
The difference between return and exit() is that return only ends the
current function, while exit() ends the whole program. In main(),
return and exit() are identical.
As for the numbers, 0 means successful completion. 1 is non-standard,
and can mean whatever the implementation pleases. For standard code,
use EXIT_SUCCESS and EXIT_FAILURE.
_EXIT() is a non-standard implementation-specific function.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
Joona I Palaste <pa*****@cc.helsinki.fi> wrote: QQ <ju****@yahoo.com> scribbled the following: I know there are many functions that I can exit the program such as return 0, exit(0), exit(1),_EXIT(0) ....
What are the difference between them?
Thanks a lot!
The difference between return and exit() is that return only ends the current function, while exit() ends the whole program. In main(), return and exit() are identical.
Only in a sane program. If you call main() recursively (or, even worse,
indirectly recursively), returning from main() will only return from the
current invocation, and exit() is (more or less) equivalent to a return
from the outermost (i.e., first) call of main().
And then there is the jolly trick of using atexit() functions which
require that local variables in main() still exist, or similar
perversions using setbuf().
Clearly, neither of these behaviours are in the least recommendable in a
well-behaved, sanely written C program. But they can occur, and when
they do, there is a difference between exit() and return from main().
Richard
"QQ" <ju****@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com... I know there are many functions that I can exit the program such as return 0,
'return' is not a function, it's a keyword. The only
way to use 'return' to terminate your program is to
write it inside the function 'main()'.
exit(0), exit(1),_EXIT(0) ....
'exit()' is a standard C function, _EXIT() is not. What are the difference between them?
You can use the function 'exit()' to terminate your
program at any point where an executable statement
is valid (i. e. inside a function body, which need
not be that of 'main()'.) The only portable arguments
for 'exit()' are zero (0), and 'EXIT_SUCCESS' or
'EXIT_FAILURE' (those are macros declared by <stdlib.h>).
Which C book(s) are you reading which don't explain this?
-Mike
QQ wrote: I know there are many functions that I can exit the program such as return 0, exit(0), exit(1),_EXIT(0) ....
What are the difference between them?
"return 0" will exit some functions. exit(0) will exit a program.
The rest will cause undefined (or possibly implementation defined)
behaviour.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
In article <bq**************@newsread1.news.pas.earthlink.net >,
"Mike Wahler" <mk******@mkwahler.net> wrote: "QQ" <ju****@yahoo.com> wrote in message news:11*********************@z14g2000cwz.googlegro ups.com...I know there are many functions that I can exit the program such as return 0,
'return' is not a function, it's a keyword. The only way to use 'return' to terminate your program is to write it inside the function 'main()'.
exit(0), exit(1),_EXIT(0) ....
'exit()' is a standard C function, _EXIT() is not.
Perhaps he meant _Exit(), which is defined in C99. _Exit() will not
call functions registered with atexit() nor any registered signal
handlers. Most of the rest of its behavior is implementation-defined.
Cheers,
- jonathan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Maximus |
last post by:
Hi,
I was just wondering, is it good to use return without arguments in a void
function as following:
void SetMapLayer()
{
if( !Map ) return;
layer = LAYER_MAP;
}
|
by: John Black |
last post by:
Hi,
I wonder what is the difference between ending the main() with and
without exit(0)?
My code is like this flow,
class ClassA{
ClassB* cb;
int toExit();
|
by: Darklight |
last post by:
if the exit() function is contained in stdlid.h
why if i remove the above header file the exit
function still works and i can still compile
program without any error messages using cc file.c
if i...
|
by: jwaixs |
last post by:
Hello,
I was wondering, what's the difference between exit and return in the
main() function? For me they both look the same, or aren't they? And if
they aren't, which should I use in which...
|
by: John Williams |
last post by:
VB .Net 2003, .Net Framework 1.1, Windows XP Pro SP1
I've written a console application which I run as a scheduled task. How do
I return an exit status value (or string) from the application so...
|
by: Wardeaux |
last post by:
Hope this is easy... I have a simple winform app that does some work and then
exits... I need to return a value to the calling app/process to indicate
completion status... what's the...
|
by: asearle |
last post by:
Hallo everyone,
I have a perl script which can return error codes. I have done this with, for example, 'exit 11;', which would (I imagine) send the exit code 11 (instead of 0) back to the calling...
|
by: gnuist006 |
last post by:
I have some code like this:
(if (test)
(exit)
(do something))
or
(if (test)
|
by: Laurent Deniau |
last post by:
I would like to know if the use of the pointer ref in the function
cleanup() below is valid or if something in the norm prevents this
kind of cross-reference during exit(). I haven't seen anything...
|
by: mathieu |
last post by:
Hi there,
I am trying to reuse a piece of code that was designed as an
application. The code is covered with 'exit' calls. I would like to
reuse it as a library. For that I renamed the 'main'...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |