c - 结构体编译时错误

标签 c compiler-errors

我编写了一个程序来捕获 <ctrl> + <c>信号,然后输出一个列表,但我有一个编译时错误,我似乎无法克服。我不断收到此错误:

cannot convert `void ()()' to `void (*)(int)' in assignment

根据编译器的说法,此行代码发生错误:

    handler.sa_handler = handle_SIGINT;

这也是周围的代码:

cmdcounter = 1;

/*set up the signal handler*/
struct sigaction handler;
handler.sa_handler = handle_SIGINT;
sigaction(SIGINT, &handler, NULL);

strcpy(buffer, "Caught <ctrl><c>\n");

handle_SIGINT在程序的前面定义:

void handle_SIGINT()
{
    write(STDOUT_FILENO, buffer, strlen(buffer));

    // Print out last 10 commands that were used.
    printf("Most recent commands entered:\n");
    if(cmdcounter <= 10) {
        for (i=0; i < cmdcounter; i++) {
            printf("%d. %s\n", i+1, cmd[i]);
        }
    }
    else {
        for (i = cmdcounter-10; i < cmdcounter; i++) {
            printf("%d. %f\n", i, cmd[i]);
        }
    }
}

在我看来一切都很好,但有些东西显然不是。有谁知道是什么引发了这个错误?

最佳答案

你的函数handle_SIGINT是错误的。

向我们展示该函数,我们将能够准确地告诉您它的错误所在。

handle_SIGINT 假设为:

void handle_SIGINT(int){....}

您遗漏了 int 部分作为参数。

关于c - 结构体编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10761884/

相关文章:

java - Java方法不断给我: “cannot find symbol” [duplicate]

c++ - 尝试编译C++代码时出现歧义错误

java - 关于泛型函数的泛型错误语法 Java 1.7

c - 为什么字符串的字节大小比长度长?

c - Unix Fork 奇怪的行为

c - 哪里可以在线阅读C99官方语言标准手册/引用/规范?

c - 如何一次性读取所有CPU核心的频率?

dictionary - 为什么这个字典功能不起作用

C While 循环 - 检查函数

compilation - Raspberry Pi : undefined references to COMXImage and g_OMXImage上的XBMC 13.2链接器错误