c - 参数计数正确时参数太少无法运行

标签 c linux linux-kernel kernel

一年前就有这样的问题,一直没有人回答。我不会在旧线程上问一个新问题,而是要打开一个新问题。无论如何,关于这个问题。

在为 Linux 编译 Zen 内核时,我在 make-kpkging 内核源代码时遇到了这个错误:

arch/x86/platform/intel-mid/early_printk_intel_mid.c: In function ‘dw_kmsg_dump’:
arch/x86/platform/intel-mid/early_printk_intel_mid.c:121:3: error: too few arguments to function ‘early_mrst_console.write’
   early_mrst_console.write(&early_mrst_console, line, len);

这是 early_mrst_console.write 的代码(early_mrst_console 是一个struct,顺便说一下,它的write 有一个指向函数early_mrst_spi_write 的链接> 函数):

static void early_mrst_spi_write(struct console *con, const char *str,
                    unsigned n)
{
    int i;

    for (i = 0; i < n && *str; i++) {
        if (*str == '\n')
            early_mrst_spi_putc('\r');
        early_mrst_spi_putc(*str);
        str++;
    }
}

现在,我不是 C 专家(甚至不是业余爱好者,真的),但看起来 early_mrst_spi_write 有 3 个参数,并且对它的调用给出了 3 个参数。为什么它调用错误,我该如何更改它以解决问题?

编辑:根据要求,struct:

struct console early_mrst_console = {
    .name =     "earlymrst",
    .write =    early_mrst_spi_write,
    .flags =    CON_PRINTBUFFER,
    .index =    -1,
};

最佳答案

给我们“struct console”的定义。我想它的写入需要更多参数。

一些编译器可能不会根据其设置给出有关分配不兼容类型函数的警告。

在任何情况下,当决定参数的数量和类型是否正确时,编译器只会查看它在 struct console 中的内容,而不会关心您如何声明 early_mrst_spi_write(这在 early_mrst_console 的初始化过程中可能很重要,并且可能会给出一个警告)。

关于c - 参数计数正确时参数太少无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352003/

相关文章:

java - 终止 Java 进程并重新启动

c++ - 通过COM端口与ModEEG通信

c - C ABI 是否要求使用堆栈将参数传递给函数?

c++ - 如何在 ubuntu 中使用 C++ 打开 "Open directory"GUI?

linux - Grep 用另一个过滤一个文本文件(非常大的文件)

linux - 将 pthread 固定到单个核心

linux - uboot : Overwrite mmcboot environment variable not working

c - Xlib 的全局热键

c - 解释一下下面代码的输出?

c - 我如何使用linux在c中使用fork()来实现我想要的输出?