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 27987
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |