Compiler Error in CPP (invalid conversion from ‘void ()()’ to ‘__sighandler_t {aka void ()(int)}

I'm using semaphore commands for creating, terminating (etc.) semaphore. Bu when I compile It gives an error. How can I fix it? I got error in line 52 (). I edited my code. I deleted librarires. It doesn't give an error about libraries. My problem about this line (mysigaction.sa_handler = (void*)mysignal;)

void mysignal(void)
{
}
void sem_signal(int semid, int val)
{
    struct sembuf semafor;
    semafor.sem_num = 0;
    semafor.sem_op = val;
    semafor.sem_flg = 1;
    semop(semid, &semafor, 1);
}
void sem_wait(int semid, int val)
{
    struct sembuf semafor;
    semafor.sem_num = 0;
    semafor.sem_op = (-1 * val);
    semafor.sem_flg = 1;
    semop(semid, &semafor, 1);
}
void mysigset(int num)
{
    struct sigaction mysigaction;
    mysigaction.sa_handler = (void*)mysignal;
    mysigaction.sa_flags = 0;
    int sonsem = 0;
    sigaction(num, &mysigaction, NULL);
} 

1 answer

  • answered 2018-04-14 14:29 Janne Husberg

    sa_handler takes a void()(int) not the void()() that you're trying to pass in. Change your handler to be defined as:
    void mysignal(int signum)