www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/03/01:48:44

From: Jack Klein <jackklein AT spamcop DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Error: Implicit declaration of function
Message-ID: <KG=ZOQCTuxdoNO3PrfaPdTbyOwtP@4ax.com>
References: <Lk7C5.14267$YG5 DOT 29312 AT tor-nn1 DOT netcom DOT ca>
X-Newsreader: Forte Agent 1.6/32.525
MIME-Version: 1.0
Lines: 44
Date: Tue, 03 Oct 2000 05:33:14 GMT
NNTP-Posting-Host: 12.75.159.104
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc04-news.ops.worldnet.att.net 970551194 12.75.159.104 (Tue, 03 Oct 2000 05:33:14 GMT)
NNTP-Posting-Date: Tue, 03 Oct 2000 05:33:14 GMT
Organization: AT&T Worldnet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Mon, 2 Oct 2000 17:48:46 -0400, "Daniel"
<cdnhermit DOT msn AT attcanada DOT net> wrote in comp.os.msdos.djgpp:

> Hello, I have a simple application that does not compile because of this
> function:
> print_result(a, x, power_for(a, x));
> 
> which cause the following error:
> app.cc(23) Error: Implicit declaration of function 'int power_for(...)'
> 
> Here is part of the code:
> int main() {
>     int x;
>     double a;
> 
>     get_input(a, x);
>     print_result(a, x, power_for(a, x));
> ......
> 
> The function does return a double [ double power_for(double a, int x){  ]
> of course, the function power_for(a, x) is define in another file
> 
> Is there a way to deal with that kind of problem?  Please note that it
> compiles without any error with Borland 5.02.
> 
> Thank you
> Daniel

In C++ it is illegal to call a function without a prototype in scope.
This is different than it is from C, where it is legal but only if the
function meets certain requirements, one of which is that the return
type must be int.

So in both C and C++, you must have a prototype in scope to call a
function that returns anything other than int.

Just add a prototype to the source file that calls the function,
before the function call:

double power_for(double, int);

Jack Klein
-- 
Home: http://jackklein.home.att.net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019