Operating System - Linux
1828578 Members
3300 Online
109982 Solutions
New Discussion

Re: warning 604: Pointers are not assignment-compatible

 
SOLVED
Go to solution
Joel Shank
Valued Contributor

warning 604: Pointers are not assignment-compatible

I am trying to write a C program to trap signals. I have used signal(SIGNIT,proc); and sigaction(SIGINT, &new_action, NULL), setting new_action.sa_handler = proc;, where proc is the handler function defined as void proc(void);

In both cases, the compiler issues this message. Using the signal code, it flags the signal(SIGINT,proc) line, using the sigactions, it flags the new_action.sa_handler = proc; line. The program works just fine (catches the signal), but I would like to get rid of the warning message and understand why I am getting it.

Can anyone help?

Thx,
jls
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: warning 604: Pointers are not assignment-compatible

Try something close to this. Note the the signal handler expects 1 arg rather than a void list.
--------------------------------------------


#include
#include
#include
#include



void Handler(int sig)
{
(void) signal(sig,Handler); /* reset Handler */
(void) printf("Received signal %d\n",sig);
return;
} /* Handler */

int main()
{
int i = 0;
void (*oldsig)(int sig) = SIG_DFL;

oldsig = signal(SIGINT,Handler);
for (i = 1; i <= 10; ++i)
{
(void) printf("Press Ctrl-C to n'rupt %d\n",i);
(void) sleep(1);
}
(void) signal(SIGINT,oldsig);
return(0);
}


--------------------------------------------
If it ain't broke, I can fix that.
Joel Shank
Valued Contributor

Re: warning 604: Pointers are not assignment-compatible

That did it! It now works both ways without any warnings.

Thanks much.

jls
Joel Shank
Valued Contributor

Re: warning 604: Pointers are not assignment-compatible

Works!
Matti_Kurkela
Honored Contributor

Re: warning 604: Pointers are not assignment-compatible

You don't need to use both signal() and sigaction(): use either one or the other. According to signal(2) man page, sigaction() is preferred for new applications.

The type of your signal handler function is slightly wrong: it should be defined as void proc(int);
The integer will be a signal number. This is so that you can code one "master signal handler" function and register it to catch all signals you're interested in, and the handler function can tell which signal it is processing.

This difference in types might be the cause of the warning.
MK
Joel Shank
Valued Contributor

Re: warning 604: Pointers are not assignment-compatible

I didn't use both at the same time. I saw that in the man pages. I tried both methods to see if the same error occurred, and it did. This indicated to me that I was doing something wrong, which now has been corrected.

Thanks for watching out for me :-)