c - gcc - 参数 "buf"与原型(prototype)不匹配

标签 c linux gcc

在这个函数中

    char *function(buf,salt)
    char *buf;
    char *salt;
    {
        function_body
    }

我收到此错误

error: argument "buf" doesn't match prototype
error: prototype declaration
argument "salt" doesn't match prototype
error: prototype declaration

这是实际的代码:

    char * function(const char *, const char *);

    char *buffer = NULL;

    buffer = function(arg1, arg2);

最佳答案

您在某处有一个 function() 的原型(prototype)声明,但实际的函数声明与它不匹配。在您的情况下,参数(类型)是不同的。

通常,错误会显示原型(prototype)的位置。查找它并将其与您的函数声明进行比较。函数参数及其类型必须完全相同。

在您更新的问题中,您说原型(prototype)定义为:

char * function(const char *, const char *);

所以你还需要将实际函数定义为

char *function(const char *buf, const char *salt)
{
    // function_body
}

(它需要相同,因此包括 const 语句!)

关于c - gcc - 参数 "buf"与原型(prototype)不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441002/

相关文章:

C 使用字符指针

linux - 无法使用 Paramiko 的 sudo 命令的交互式远程密码输入

regex - 使用正则表达式表达日期和时间的方法 : YYYY-MM-DD HH:MM:SS. XXX

linux - Linux 上 dlopen() 的有效相对路径?

gcc - 我怎样才能让 ARM MULL 指令在 gcc 的 uint64_t 中产生它的输出?

c - 我收到错误请帮助我解决此错误..我在下面编写了代码

c - 判断两组整数是否相同,比N log(N)更快

c - 如何将无符号 24 位 int 转换为有符号 int 并将符号扩展为 32 位?

c - 为什么 RAND_MAX 在 linux 和 windows 的同一台机器上不同?

ubuntu - 编译期间使用了错误的 gcc 版本