function - Error in c programme conflicting types for xx and previous implicit declaration of xx was here -
function - Error in c programme conflicting types for xx and previous implicit declaration of xx was here -
suppose have file insert.c in 2 functions defined: 1.insert_after 2.insert_before
the definitions of these func this:
insert_after(arg1) { if(condition 1) { ......... } else insert_before(arg1); } insert_before(arg) { if(condition 1) { ......... } else insert_after(arg); }
now if file insert.c included in main.c , insert_after function called
# include "insert.c" int main() { insert_after(arg); homecoming 0; }
on compiling main.c using gcc,the next error encountered:
conflicting types ‘insert_before’
note: previous implicit declaration of ‘insert_before’ here
what wrong here , how avoid it?
this because don't declare prototypes functions. function has no prototype, default, has unknown set of arguments , returns int. not case insert_before
.
create file insert.h
in declare them:
#ifndef insert_h #define insert_h void insert_before(type_of_arg); void insert_after(type_of_arg); #endif /* insert_h */
and include file @ top of insert.c
.
you should compile with:
gcc -wall -wstrict-prototypes -wmissing-prototypes -o progname insert.c main.c
c function
Comments
Post a Comment