LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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: 31
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
LQ 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: 31
Thanks for the info, I'll keep that in mind
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:24 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration