Download your favorite Linux distribution at LQ ISO.
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 07-12-2006, 08:49 AM   #1
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Rep: Reputation: 38
compiler warning!

I have this code

int fd =-1;
fd = openPort(fd);

and I get "warning: implicit declaration of function in 'openPort'"

So i guess its nothing to bather about or?

The program works fine.
Old 07-12-2006, 08:57 AM   #2
Registered: Jan 2004
Location: Australia
Distribution: Debian
Posts: 168

Rep: Reputation: 30
An implicit declaration is where you have used the function without yet declaring it. To fix this, you either need to put the function declaration above it's use, or use a function prototype.

a function prototype for openPort would look like :

int openPort(int);

and needs to be placed above the usage (eg, at the top of the file)
Old 07-12-2006, 10:39 AM   #3
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Originally Posted by kalleanka
So i guess its nothing to bather about or?

The program works fine.
It really is something to be concerned about, because the compiler can't check the validity of the arguments you send to the function on the line where you invoke it. The argument list is not checked and the compiler just generates code that passes everything you give it in the invocation without making a fuss. Furthermore, implicit function declarations take the form "extern int function_name()", so anything they return will be cast to an integer. This is the only reason why your code works, because you are expecting an integer back. If you made your function return a float or something else other than an int or char (just for example's sake) I bet it wouldn't work. This is why function prototypes are important, and why header files and the #include pre-processor directive were introduced.
Old 07-13-2006, 06:42 AM   #4
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Original Poster
Rep: Reputation: 38
Thanks a lot for the explanation. Interesting.

I will sort out these problems later since I got linking problems to sort out first.


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
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 01:35 PM
C++ IDE+Compiler?Java IDE+compiler? Boby Linux - Software 3 05-31-2005 02:12 PM
Compiler conundrum: Which came first, a compiler, or it's source code? fr0zen Programming 21 01-29-2004 05:31 AM
No compiler to compiler the compliler NewtonIX Linux - Newbie 13 11-03-2003 06:32 AM
compile a compiler without a compiler? lackluster Linux - General 18 01-02-2003 08:55 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:38 AM.

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