70,016
社区成员




/*test.c*/
int func(int a, int b, int c)
{
return(a - b - c);
}
/*test.h*/
extern int func(int a, int b, int c);
/*test.h*/
extern int func(int a, int b);//少了一个参数
/*test.h*/
extern int func(int a);//少了2个参数
/*test.c*/
#include"test.h"
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c)
}
/*test.h*/
extern int func(int a, int b);/*Hey! It compiles!*/
//extern int func(int a);/*sorry , the code won't compile. */
/*this is why??*/
ths.[/quote]
gcc5.4 无法编译通过。
$ gcc test.c
test.c:10:5: error: conflicting types for ‘func’
int func(int a, int b, int c)
^
In file included from test.c:2:0:
test.h:2:12: note: previous declaration of ‘func’ was here
extern int func(int a, int b);/*Hey! It compiles!*/
[/quote]
好的,gcc编译的时候是我的失误,是不可以通过的,详细的声明在19楼。
感谢你的回答。
/*test.c*/
#include"test.h"
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c)
}
/*test.h*/
extern int func(int a, int b);/*Hey! It compiles!*/
//extern int func(int a);/*sorry , the code won't compile. */
/*this is why??*/
ths.[/quote]
gcc5.4 无法编译通过。
$ gcc test.c
test.c:10:5: error: conflicting types for ‘func’
int func(int a, int b, int c)
^
In file included from test.c:2:0:
test.h:2:12: note: previous declaration of ‘func’ was here
extern int func(int a, int b);/*Hey! It compiles!*/
[/quote]
gcc test.c ?
有加什么参数么?
[/quote]
没加[/quote]
好,那我明白了,昨天操作失误,声明的时候参数,给错,我的失误,现在是vs2013可以编译通过。gcc无法编译通过了。
假对函数不尽性声明,代码如下:
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c);
}
上面的代码可以运行,一旦声明了就不可以运行。假如不声明直接调用少一个实参,最后一个参数会是堆中的一个随机数,这是因为c语言不支持重载,编译器没有检测参数类型。
好的谢谢各位,结贴了。
/*test.c*/
#include"test.h"
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c)
}
/*test.h*/
extern int func(int a, int b);/*Hey! It compiles!*/
//extern int func(int a);/*sorry , the code won't compile. */
/*this is why??*/
ths.[/quote]
gcc5.4 无法编译通过。
$ gcc test.c
test.c:10:5: error: conflicting types for ‘func’
int func(int a, int b, int c)
^
In file included from test.c:2:0:
test.h:2:12: note: previous declaration of ‘func’ was here
extern int func(int a, int b);/*Hey! It compiles!*/
[/quote]
gcc test.c ?
有加什么参数么?
[/quote]
没加
/*test.c*/
#include"test.h"
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c)
}
/*test.h*/
extern int func(int a, int b);/*Hey! It compiles!*/
//extern int func(int a);/*sorry , the code won't compile. */
/*this is why??*/
ths.[/quote]
gcc5.4 无法编译通过。
$ gcc test.c
test.c:10:5: error: conflicting types for ‘func’
int func(int a, int b, int c)
^
In file included from test.c:2:0:
test.h:2:12: note: previous declaration of ‘func’ was here
extern int func(int a, int b);/*Hey! It compiles!*/
[/quote]
gcc test.c ?
有加什么参数么?
/*test.c*/
#include"test.h"
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c)
}
/*test.h*/
extern int func(int a, int b);/*Hey! It compiles!*/
//extern int func(int a);/*sorry , the code won't compile. */
/*this is why??*/
ths.[/quote]
gcc5.4 无法编译通过。
$ gcc test.c
test.c:10:5: error: conflicting types for ‘func’
int func(int a, int b, int c)
^
In file included from test.c:2:0:
test.h:2:12: note: previous declaration of ‘func’ was here
extern int func(int a, int b);/*Hey! It compiles!*/
/*test.c*/
#include"test.h"
int main()
{
int i=5;
func(i,i);
return 0;
}
int func(int a, int b, int c)
{
return (a - b - c)
}
/*test.h*/
extern int func(int a, int b);/*Hey! It compiles!*/
//extern int func(int a);/*sorry , the code won't compile. */
/*this is why??*/
ths.