Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-12-2005, 11:02 PM   #1
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Rep: Reputation: 15
why warning is shown for exit()

When I use exit() function in loops I'm getting the warning

copy.c:13: warning: incompatible implicit declaration of built-in function ‘exit’

Why does this happen?
Old 12-12-2005, 11:20 PM   #2
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Rep: Reputation: 30
Not sure, being a newbie myself, but I think you have to declare the function before using it. Try int exit()

Edit: You are programming C, right?
Old 12-12-2005, 11:48 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
#include <stdlib.h>

man 2 exit =>
_EXIT(2) Linux Programmer's Manual _EXIT(2)

_exit, _Exit - terminate the current process

#include <unistd.h>

void _exit(int status);

#include <stdlib.h>

void _Exit(int status);

The warning should go away if you #include <stdlib.h> (which, in turn, has the correct function prototype for "exit()").

Just FYI, you should *not* try to declare your own functions if there's a valid header available - ALWAYS try to use an existing header file FIRST.

I was recently using the binary of a product that was compiled under Linux 2.4 ... and WOULD NOT WORK under Linux 2.6 ... all because the programmer innocently coded "extern errno" instead of "#include <errno.h>".

Moral: If there's a header, use it. If you don't know what the header is, look it up ("man", MSDN DevHelp ... or even Google, if necessary).

Old 12-12-2005, 11:51 PM   #4
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Rep: Reputation: 30
Thanks for the info, I'll keep that in mind


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between exit 1 and exit kushalkoolwal Programming 6 10-20-2005 03:56 PM
[SOLVED] Time shown incorrect? druuna LQ Suggestions & Feedback 8 03-30-2005 03:15 PM
why old java version is shown instead of new one ?? emailssent Linux - Software 2 03-01-2005 12:32 AM
File on cd not shown esher2292 Linux - General 3 05-23-2004 02:51 PM
no directories shown in root oasisbhrnw99 Linux - Newbie 1 05-05-2004 01:09 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration