gpt4 book ai didi

c - 在 C 中获取 "conflicting types for function",为什么?

转载 作者:太空狗 更新时间:2023-10-29 16:16:13 26 4
gpt4 key购买 nike

我正在使用下面的代码:

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 的实现在这里并不重要。当我尝试编译上面的代码时,我得到了这两个异常:

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 行之前添加一个函数原型(prototype):

char* do_something(char*, const char*);

或者您需要将函数定义移动到 printf 行上方。您不能在函数声明之前使用它。

关于c - 在 C 中获取 "conflicting types for function",为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1549631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com