结构sigaction的不完整的错误 [英] struct sigaction incomplete error

查看:617
本文介绍了结构sigaction的不完整的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然包括< signal.h中> 我得到一个错误,指出结构的sigaction 是一个不完整的类型。

我不知道该怎么做了。

请帮忙

 的#include<&signal.h中GT;
结构sigaction的行为;INT主(INT ARGC,字符** argv的)
{
    INT深度;    / *验证参数的数目* /
    如果(的argc 2)
    {
        的printf(致命的错误:请使用参数< MaxChild><&MAXDEPTH GT; \\ n);
        出口(1);
    }    / *注册实时信号处理的SIGCHLD * // * 173 * /
    memset的(安培;行为,0,sizeof的(行为));
    act.sa_handler = sigproc;
    的sigaction(SIGCHLD,/ *其作用将被改变的信号数* /
             &安培;行为,/ *做新的动作时,SIGCHLD到来* /
             空值); / *旧的行动 - 没有存储* /
    函数srand(时间(NULL));
    深度=兰特()%的atoi(argv的[2]); / * [0 MAXDEPTH] * /    RecursiveFunc(与atoi(ARGV [1]),深度);    返回0;
}

错误消息:

  proc.c:在函数'主':
proc.c:173:22:错误:'sizeof的不完全型'结构sigaction的无效的应用
proc.c:174:2:错误:无效使用不确定型结构的sigaction的
CC1:警告被视为错误
proc.c:175:2:错误:函数的sigaction'隐式声明


解决方案

只是

 的#define _XOPEN_SOURCE

在code任何其他线路,或与 -D 选项来定义preprocessor符号编译之前

  GCC ... ... -D_XOPEN_SOURCE

Although including <signal.h> I get an error saying that struct sigaction is an incomplete type.

I have no Idea what to do with it.

Please help

#include <signal.h>
struct sigaction act;

int main(int argc, char** argv)
{
    int depth;

    /* validate arguments number*/
    if(argc < 2)
    {
        printf("fatal error: please use arguments <MaxChild> <MaxDepth>\n");
        exit(1);
    }

    /* register the realtime signal handler for sigchld*/

/*173*/
    memset(&act,0,sizeof(act));
    act.sa_handler = sigproc;
    sigaction(SIGCHLD,  /* signal number whose action will be changed */
             &act,      /* new action to do when SIGCHLD arrives*/
             NULL);     /* old action - not stored */


    srand(time(NULL));
    depth = rand() % atoi(argv[2]); /* [0 maxDepth]*/

    RecursiveFunc(atoi(argv[1]), depth);

    return 0;
}

The error messages:

proc.c: In function ‘main’:
proc.c:173:22: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’ 
proc.c:174:2: error: invalid use of undefined type ‘struct sigaction’
cc1: warnings being treated as errors
proc.c:175:2: error: implicit declaration of function ‘sigaction’

解决方案

Just

#define _XOPEN_SOURCE

before any other line in your code, or compile with the -D option to define the preprocessor symbol

gcc ... -D_XOPEN_SOURCE ...

这篇关于结构sigaction的不完整的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆