This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
problem with function declaration and definition mismatch using GCC
- From: 阎淼 <yanmiaobest at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Jul 2009 11:36:09 +0800
- Subject: problem with function declaration and definition mismatch using GCC
Hi,
I am using GCC 4.1.2 on a project, the prototype and definition of a
function is mismatch, but the programs
compiles and works fine, how GCC compiles following code and checks
the prototype ?
in file a.h :
typedef struct {...} struct_b;
extern int func_A ( struct_a * socket, struct_b * flash);
in file a.c:
#include "a.h"
int func_A( struct_a * socket, struct_b vol)
{
.....
vol.read = read;
vol.write = write;
.....
return 0;
}
and another file b.c:
#include "a.h"
int func_B(.....)
{
struct_b flash;
func_A( ..., &flash);
flash.read(xxx);
}
GCC compiles this piece of code without warnings, and it works fine.
But there is a mismatch between declaration and definition of
func_A,
should there be a warning ? I compiled the code with -ansi and -Wall
options. And when I changed the prototype to
extern int func_A ( struct_a * socket, struct_b * vol), GCC gives
a error saying conflicting types of func_A.
Best Regards!
Miao Yan