error: implicit declaration of function `func_name'

D

DanielJohnson

I call a function which is named as func_name in file /source/folderA/
fileA.c.

The actual function definition is in /source/folderB/fileB.c.

And I get this error.

warning: implicit declaration of function `func_name'
***Error Code 1

I know that I have to include the file in fileA.c but the library in
which I am working on is clean, i.e. there are no cross includes like
that.

Any other option to do that.
 
S

santosh

DanielJohnson said:
I call a function which is named as func_name in file /source/folderA/
fileA.c.

The actual function definition is in /source/folderB/fileB.c.

And I get this error.

warning: implicit declaration of function `func_name'
***Error Code 1

I know that I have to include the file in fileA.c but the library in
which I am working on is clean, i.e. there are no cross includes like
that.

Any other option to do that.

Yes. Include the correct prototype for func_name in a header and include
that header in fileA.c
 
R

Richard Tobin

DanielJohnson said:
I know that I have to include the file in fileA.c but the library in
which I am working on is clean, i.e. there are no cross includes like
that.

Why do you think it is "unclean" to include the necessary header?

If your program has a structure you consider unclean, then restructure
the program. Don't try to hide the dirtiness by not including the
necessary headers.

-- Richard
 
R

rahul

I call a function which is named as func_name in file /source/folderA/
fileA.c.

The actual function definition is in /source/folderB/fileB.c.

And I get this error.

warning: implicit declaration of function `func_name'
***Error Code 1

If your function is "int foo(int a)" either declare that in a header
and include the header:
/* foo.h */
#ifndef _FOO_H
#define _FOO_H
int foo(int a);
#endif

/* fileA.c */
#include "foo.h"

or declare the function in your source file:
/* fileA.c */
extern int foo(int );

Including header is cleaner than the extern declarations. If the
function prototype is not encountered, a standard complying compiler
is required to show diagnostics. Before standardization, prototypes
were not required and functions were assumed to be returning int with
variable number of arguments.
I know that I have to include the file in fileA.c but the library in
You don't include the .c files but the header files.
which I am working on is clean, i.e. there are no cross includes like
that.
What do you mean by a cross include?
 
S

santosh

rahul wrote:

Before standardization, prototypes
were not required and functions were assumed to be returning int with
variable number of arguments.

I suppose it would be more correct to say that before standardisation
function declarations specified the function name and return type and
that it took unspecified arguments.

<snip>
 
R

rahul

rahul wrote:



I suppose it would be more correct to say that before standardisation
function declarations specified the function name and return type and
that it took unspecified arguments.

<snip>

Yup...that would be more appropriate...
 

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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top