#include <stdio.h>
void (*handler)( int );
int main( int argc, char **argv ){
/*
char c;
signal( SIGSTOP, handler(0) );
for(;;){
c = getchar();
putchar( c );
}
*/
return 0;
}
void handler( int num ){
printf( "Process stopped\n" );
}
Here's the problem: When I run the code (keep in mind the signal part is commented out; I'll get to that later) the compiler says:
sig.c:17: error: 'handler' redeclared as different kind of symbol sig.c:3: error: previous declaration of 'handler' was here
So evidently, both the prototype and the function defintion count as declarations of the pointer. I can't have only one of them, obviously, but if I have both of them, it's declared twice.
The second problem is that signal() takes a function with a void return type as its input, but when I compile it (with comments removed) it says it can't use a void output as a parameter (makes sense, but why would it require a void-typed function in the first place?)
I've already tried defining the function as
void (*handler)( int num ){
and it didn't work.So my three questions are:
1. What is the syntax for a prototype of a function declared through its pointer?
2. What is the syntax for the function definition of a function declared through its pointer?
3. Which is the actual declaration of the function: the prototype or the definition?


Sign In
Create Account


Back to top









