473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

exit()

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 use cc -Wall file.c i get error message
file.c:18: warning: implicit declaration of function `exit'
but program will still run and function properly
Nov 14 '05 #1
7 6995
Darklight <ng********@netscape.net> wrote:
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
Without appropriate flags telling the compiler to output warnings
many compilers only output messages for errors. Having no declaration
in scope for a function isn't an error, the compiler will assume by
default that that function is going to return an int (at least if you
use a non-C99 compiler).
if i use cc -Wall file.c i get error message
file.c:18: warning: implicit declaration of function `exit'
but program will still run and function properly


You're lucky. Even though the compiler had no information on what
arguments exit() takes and it had to make a mistake in the assumption
on what exit() returns (but, due to the nature of exit(), it's rather
unimportant) it seems to have been able to produce a correct input
file for the linker. And the linker doesn't care about declarations
anymore, it just finds exit() in the C standard library of your
system and makes the final executable use that.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
Darklight wrote on 03/09/04 :
if the exit() function is contained in stdlid.h
It's not. A header only contains function declaration (in prototype
forms since 1989). Please reread your C-book.
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 use cc -Wall file.c i get error message
file.c:18: warning: implicit declaration of function `exit'
but program will still run and function properly


This is because the body of the function is elswere (probably in some
library)

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"

Nov 14 '05 #3
On Fri, 3 Sep 2004 10:45:54 +0000 (UTC)
Darklight <ng********@netscape.net> wrote:
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 use cc -Wall file.c i get error message
file.c:18: warning: implicit declaration of function `exit'
but program will still run and function properly


The exit function isn't contained in stdlib.h it is only declared there.
The actual function is either compiler magic of contained in the
standard library.

The warning when using -Wall is the compiler being helpful.

Please note that with some functions you invoke undefined behaviour if
you don't have an appropriate declaration in scope and there are real
systems where this can cause the software to fail. Even for the
functions where it does not automatically invoke undefined behaviour it
prevents the compiler from warning you if the parameters are incorrect
(such as not passing any to exit) so you should always include the
relevant header even if you can get away without it.

Also, if using gcc (which -Wall suggests to me you might be) you might
want to consider:
gcc -ansi -pedantic -Wall -O file.c
This will make gcc comply with the C89 (or possibly C95) standard and
generate additional helpful warnings.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #4
Flash Gordon wrote:

gcc -ansi -pedantic -Wall -O file.c


Thanks for that
Nov 14 '05 #5
Darklight wrote:
Flash Gordon wrote:
gcc -ansi -pedantic -Wall -O file.c


Thanks for that


I use "gcc -W -Wall -ansi -pedantic -Wwrite-strings -O1"

--
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Nov 14 '05 #6
Darklight <ng********@netscape.net> wrote:
# if the exit() function is contained in stdlid.h
# why if i remove the above header file the exit

If you don't define or declare a function, it is implicitly declared as
int functionname();
(Returns int, takes an indefinite number of parameters converted with some
default promotions.)

If the function definition is compatiable with the implicit declaration,
it will work.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
You hate people.
But I love gatherings. Isn't it ironic.
Nov 14 '05 #7
In <41***************@yahoo.com> CBFalconer <cb********@yahoo.com> writes:
Darklight wrote:
Flash Gordon wrote:
gcc -ansi -pedantic -Wall -O file.c


Thanks for that


I use "gcc -W -Wall -ansi -pedantic -Wwrite-strings -O1"


I don't. As the man page says, there are very good reasons -W and
-Wwrite-strings have not been included into -Wall.

If someone wants to bring gcc even closer to ANSI C conformance on x86,
-ffloat-store should be added to the original set of options. But it
slows down floating point code.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ivan Voras | last post by:
In a code such as: if len(sys.argv) < 2: print "I need arguments!" sys.exit(1) Is sys.exit() really a good choice? Is there something more elegant? (I tried return but it is valid only in a...
1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
16
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...
11
by: yawnmoth | last post by:
To quote from <http://php.net/function.include>, "Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value." ...
11
by: =?Utf-8?B?U3RldmVEQjE=?= | last post by:
Hi all. I'm using VS 2008 Express C++. I created a console application back in 1999, and updated it for VC++ 6.0 in 2001. I've updated again this past month, and have found enough differences...
39
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'...
0
by: Gary Robinson | last post by:
In Python 2.5.2, I notice that, in the interpreter or in a script, I can exit with: exit() But I don't see exit() mentioned as a built-in function; rather the Python Library Reference says we...
0
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.