LinuxQuestions.org
Visit Jeremy's Blog.
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 07-12-2006, 07:49 AM   #1
kalleanka
Member
 
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, 07:57 AM   #2
urzumph
Member
 
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, 09:39 AM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Quote:
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, 05:42 AM   #4
kalleanka
Member
 
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.
 
  


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

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

All times are GMT -5. The time now is 09:59 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