首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为posix配置C99

为posix配置C99
EN

Stack Overflow用户
提问于 2016-01-23 05:37:39
回答 1查看 395关注 0票数 0

我正在练习信号,我已经从gcc移到了乌本图上,我遇到了一些问题。下面是gcc为eclipse编译的代码,我得到了错误" error :在类型‘void(*)(Int)’中为类型‘union’赋值时不兼容的类型。

在网上,我看到了错误的机会,因为编译器使用了预C99版本。因此,我尝试将eclipse编译成C99版本,并在下面的链接How do you configure GCC in Eclipse to use C99?中找到

我试图按SO link中的建议进行更改,但目前我的其他标志有一行,上面写着“-c -fmessage-length =0”。

如果我按照post的建议在该行之前或之后添加-std=c99,编译器将无法找到文件本身

我假设由于编译器使用了预C99版本而导致了错误。如果我在追逐错误的方向,请纠正我,如果它是正确的,那么添加-std=c99到标志选项的正确方式是使用C99。

编辑:基于答案的--当我更改sig_handler参数时,我能够编译而不添加-std=c99标志,但是,按照建议,我遇到了编译错误。下面是编译行

gcc -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -MMD -MP -MF

代码语言:javascript
复制
`odd_process.d" -MT"odd_process.d" -o "odd_process.o" "../odd_process.c`"
    ../odd_process.c: In function ‘main’:
    ../odd_process.c:13:2: error: unknown type name ‘sigset_t’
    ../odd_process.c:14:19: error: storage size of ‘sa’ isn’t know

N

代码语言:javascript
复制
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void sighandler(int sig)
{
    printf("signal has been caught \n ");

}

int main(void)
{
    sigset_t block_signal, empty_signal;
    struct sigaction sa;

    pid_t childid;
    int i;

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;

   **/*for below line while running on eclipse I see error which says*/
   /***error: incompatible types when assigning to type ‘union <anonymous>’ from type ‘void (*)(int)’** */**

**sa.__sigaction_handler = sighandler;**

    stdbuf(stdout, NULL);

    if (sigaction(SIGCHLD, &sa, NULL) == -1)
    {
        printf("value not passed to signal handler \n ");
    }

    sigemptyset(&block_signal);
    sigaddset(&block_signal, SIGCHLD);

    if (sigprocmask(SIG_SETMASK, &block_signal, NULL) == -1)
    {
        printf("error occurred while setting signal mask \n");
    }

    childid = fork();

    printf("value of child id is -- %d ", childid);

    switch(childid)
    {
        case -1:
            printf("Error condition child creation did not happen properly \n");
            exit(-1);
        case 0:
            printf(" Child got created and will print odd number !!! ");
            sleep(5);
            exit(1);
        default:
            printf(" parent gets created !!! \n ");
            break;
    }

    sigemptyset(&empty_signal);
    sigsuspend(&empty_signal);
    printf(" parent will print  \n ");

    for(i = 0; i < 10; i++)
    {
        printf("%d ", i);
    }

    printf("\n");

    return EXIT_SUCCESS;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-23 07:23:53

修改CFLAGS,(打开所需的项目)。

  1. 单击菜单项project
  2. 单击下拉菜单项properties
  3. 单击左侧窗口中的C/C++Build选项卡以展开
  4. 单击展开Settings中的C/C++Build选项卡
  5. 单击第二列中的GCC C Comiler选项卡以展开
  6. 单击第二列中的miscellaneous选项卡以选择第三列
  7. 选择“其他旗线”
  8. 输入附加标志,如-std=gnu99
  9. 单击ok

这可能需要在每个项目中完成。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34960039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档