开发者

How do I resolve the compiler error: invalid use of void expression? [closed]

开发者 https://www.devze.com 2023-01-10 12:08 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.
turtle(int fd,int sec1,int turtle_speed){

     signal(SIGUSR1,handle(fd,turtle_speed));

    struct timeval b;

    int flag=1,turtle_current_pos,turtle_previous_pos=0,sec2;

    turtle_current_pos=0;

    while(turtle_current_pos<100){

            sleep(2);

                gettimeofday(&b,NULL);

    sec2=b.tv_sec;

    //printf("%d\n",sec2);

    turtle_开发者_JS百科current_pos=(sec2-sec1)*turtle_speed;
    fflush(stdout);

    if((turtle_current_pos-turtle_previous_pos)>=1){
        turtle_previous_pos=turtle_current_pos;
        print('T',turtle_previous_pos);
    }
    }
}


The problem is the first line. You have to pass a function pointer, while it looks like you're calling the function, which happens to have a void return type. It also looks like you want C to have closures - you're trying to pass arguments to the signal handler function. This is not possible. You'll need to store those values in global variables, and declare your signal handler with the correct prototype for a signal handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消