Newbie: previous implicit declaration problem

F

francescomoi

Hi.

I've got a function defined:
------------------
double my_function(char string1[], char string2[])
{
return 2;
}
-----

And I want to call it from my main program:
---------
char *stringA;
char *stringB;
double foo = my_function(stringA, stringB);
------

But I got this warning message:
-----------
prog02.c:64: warning: type mismatch with previous implicit declaration
prog02.c:51: warning: previous implicit declaration of `my_function'
prog02.c:64: warning: `my_function' was previously implicitly declared
to return `int'
--------
Line #51 is << double foo = my_function(stringA, stringB); >>
Line #64 is << double my_function(char string1[], char string2[]) >>

Why am I told that I declarated previously `my_function'?? I think I
din't.

Thank you very much.
 
F

francescomoi

Ooops... I forgot to create prototype:

double my_function(char string1[], char string2[]) ;

Sorry.
 
C

CBFalconer

I've got a function defined:
------------------
double my_function(char string1[], char string2[])
{
return 2;
}
-----

And I want to call it from my main program:
---------
char *stringA;
char *stringB;
double foo = my_function(stringA, stringB);
------

But I got this warning message:
-----------
prog02.c:64: warning: type mismatch with previous implicit declaration
prog02.c:51: warning: previous implicit declaration of `my_function'
prog02.c:64: warning: `my_function' was previously implicitly declared
to return `int'
--------
Line #51 is << double foo = my_function(stringA, stringB); >>
Line #64 is << double my_function(char string1[], char string2[]) >>

Why am I told that I declarated previously `my_function'?? I think I
din't.

You put the definition of the function after the point at which you
called it. Move the whole function definition before the function
containing the call to it. That way the definition also functions
as a prototype, and is automatically correct. eg:

....
double my_function(...) {
....
}

int main(void) {
....
foo = my_function(...);
....
return 0;
}

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top