LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-12-2005, 11:02 PM   #1
skie_knite007
Member
 
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
akudewan
Member
 
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
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

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

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

NAME
_exit, _Exit - terminate the current process

SYNOPSIS
#include <unistd.h>

void _exit(int status);

#include <stdlib.h>

void _Exit(int status);

DESCRIPTION
...
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).

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

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


Reply


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


All times are GMT -5. The time now is 03:34 PM.

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