Suppose I have a file insert.c in which two functions are defined:
1.insert_after
2.insert_before
The definitions of these func are something like this:
insert_after(arg1)
{
if(condition 1)
{ ......... }
else
insert_before(arg1);
}
insert_before(arg)
{
if(condition 1)
{ ......... }
else
insert_after(arg);
}
Now if this file insert.c is included in main.c and insert_after function is called
# include "insert.c"
int main()
{
insert_after(arg);
return 0;
}
On compiling main.c using gcc,the following error is encountered:
conflicting types for ‘insert_before’
note: previous implicit declaration of ‘insert_before’ was here
What is wrong here and how to avoid it?
This is because you don’t declare prototypes for your functions. A function which has no prototype, by default, has an unknown set of arguments and returns an int. But this is not the case for
insert_before.Create a file
insert.hin which you declare them:and include this file at the top of
insert.c.You should then compile with: