LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-29-2005, 03:39 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
Implicit declaration means


Hi... what should i understand reading these things?
monitor.c: In function `local_get_htb_parameters':
monitor.c:133: warning: implicit declaration of function `execl'
monitor.c: In function `get_htb_parameters':
monitor.c:144: warning: implicit declaration of function `sleep'
 
Old 08-29-2005, 03:49 AM   #2
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
The compiler has no knowledge of the signature of those functions, therefore it thinks they return int.
You should include the corresponding headers, in this case <unistd.h>.

The man pages for the functions usually says which include files they require.

EDIT: To be more precise, "implicit declaration" means that the compiler accepts whichever signature you're using for the functions, and that it expects them to return int.

Last edited by dub.wav; 08-29-2005 at 03:56 AM.
 
Old 08-29-2005, 05:14 AM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Thx a lot.. I have created those functions... Can u explain me why the unistd.h library can make it work? What this file provides?
 
Old 08-29-2005, 06:47 AM   #4
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
unistd.h provides declarations of those two functions as well as other things, see 'man unistd.h' for more details.
A practical example:
Code:
#include <stdio.h>

int main() {
	printf("%4.2lf\n", multiply(2.4, 3.5));
	return 0;
}

double multiply(double x, double y) {
	return x * y;
}
The multiply function comes after main, so when used in main it is declared implicitly.
The compiler accepts my usage, and expect the function to return int. When run, the program prints 0.00.
Note that this example doesn't compile in gcc 3.4 and 4.0, but it does in 3.2 and possibly 3.3, and in icc.

Then, we try this:
Code:
#include <stdio.h>
double multiply(double x, double y);

int main() {
	printf("%4.2lf\n", multiply(2.4, 3.5));
	return 0;
}

double multiply(double x, double y) {
	return x * y;
}
The only difference is that I've provided a declaration of the multiply function. Now the program prints 8.40.
 
Old 08-29-2005, 10:35 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
why are functions declared after main() in c (i think i remember the oppisite in c++).
i did this and it worked with cc
Code:
#include <stdio.h>

double multiply(double x, double y) {
        return x * y;
}

int main() {
        printf("%4.2lf\n", multiply(2.4, 3.5));
        return 0;
}
is there anything inherantly wrong with defining it above main()?
 
Old 08-29-2005, 11:30 AM   #6
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
No, of course not. It was just a quick example to demonstrate implicit declarations in C.
 
Old 12-05-2008, 12:51 AM   #7
devkpict
Member
 
Registered: Oct 2007
Posts: 31

Rep: Reputation: 15
Thumbs up Implicit call to function

I have the same warning after searching I found out that the function which i am calling from some other file is a static function
 
Old 03-09-2009, 06:20 AM   #8
jiikka
LQ Newbie
 
Registered: Jan 2009
Location: Chennai, India
Distribution: Redhat
Posts: 23

Rep: Reputation: 17
Talking thank you

i got the same error n i included unistd.h header file ..
now its working ..
 
  


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
warning: implicit declaration of function liguorir Linux - Software 5 10-22-2012 03:20 PM
warning: incompatible implicit declaration of built-in function ‘exit’ xzotech Programming 1 08-14-2005 05:43 AM
implicit declaration of function 'getdelim' MicahCarrick Programming 2 05-02-2005 11:03 AM
gcc 3.4.1 and c implicit declaration foo_bar_foo Programming 1 01-27-2005 04:49 PM
implicit deny in iptables tarheel92x Linux - Networking 2 11-13-2003 09:02 PM

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

All times are GMT -5. The time now is 09:42 AM.

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