获得"冲突的类型和功能QUOT;在C,为什么呢? [英] Getting "conflicting types for function" in C, why?
问题描述
我用下面的code:
char dest[5];
char src[5] = "test";
printf("String: %s\n", do_something(dest, src));
char *do_something(char *dest, const char *src)
{
return dest;
}
do_something的实现并不重要。
当我尝试编译上面我得到这两个例外:
The implementation of do_something is not important here. When I try to compile the above I get these two exception:
错误:冲突的类型'do_something'(在printf的调用)
错误:的'do_something'previous隐式声明在这里(在原型线)
"error: conflicting types for 'do_something'" (at the printf call) "error: previous implicit declaration of 'do_something' was here" (at the prototype line)
为什么?
推荐答案
您正在试图调用do_something声明之前。你需要你的printf行前添加一个函数原型:
You are trying to call do_something before you declare it. You need to add a function prototype before your printf line:
char* do_something(char*, const char*);
或者你需要移动的printf线以上函数定义。声明之前无法使用的功能。
Or you need to move the function definition above the printf line. You can't use a function before it is declared.
这篇关于获得"冲突的类型和功能QUOT;在C,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!