How do I resolve the compiler error: invalid use of void expression? [closed]
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.
精彩评论