R
Robbie Brown
I have the following code
/* declare signal as function (int, pointer to function (int) returning
void) returning pointer to function (int) returning void */
void (*signal(int, void (*)(int)) ) (int);
/* simplify things a bit using a typedef */
typedef void (*fptr)(int);
int main(void){
/* declare and define function that takes int and returns void */
void foobar(int x){
printf("%s%d\n", "x in foobar is ", x);
}
/* define signal using the typedef, compiles */
fptr signal(int x, fptr y){
return NULL;
}
/* What I'd like to do now is to replace the fptr typedef with the
pre typedef type if that makes sense.
Why? because it helps my understanding */
/* Here I can say, void y(), void (y)(), void (*y)(), void y(int),
void(y)(int) void (*y)(int) for the second arg and they all
compile */
fptr signal2(int x, void (*y)(int) ){
NULL;
}
/* finally I want to do something like
return a pointer to a function taking int and returning void
but I just can't figure out how to do it. I've tried
void (*)(int), void (int), (void (*) (int)) etc etc without
success */
/* can't get this to compile in any way */
//void (*x) (int) signal3(int x, void (*y)(int) ){
// return NULL;
//}
}
How do I code signal3 to completely get rid of my dependence on the
typedef. Once again, the only reason I want to do this is because I can
(hopefully)
Thanks
/* declare signal as function (int, pointer to function (int) returning
void) returning pointer to function (int) returning void */
void (*signal(int, void (*)(int)) ) (int);
/* simplify things a bit using a typedef */
typedef void (*fptr)(int);
int main(void){
/* declare and define function that takes int and returns void */
void foobar(int x){
printf("%s%d\n", "x in foobar is ", x);
}
/* define signal using the typedef, compiles */
fptr signal(int x, fptr y){
return NULL;
}
/* What I'd like to do now is to replace the fptr typedef with the
pre typedef type if that makes sense.
Why? because it helps my understanding */
/* Here I can say, void y(), void (y)(), void (*y)(), void y(int),
void(y)(int) void (*y)(int) for the second arg and they all
compile */
fptr signal2(int x, void (*y)(int) ){
NULL;
}
/* finally I want to do something like
return a pointer to a function taking int and returning void
but I just can't figure out how to do it. I've tried
void (*)(int), void (int), (void (*) (int)) etc etc without
success */
/* can't get this to compile in any way */
//void (*x) (int) signal3(int x, void (*y)(int) ){
// return NULL;
//}
}
How do I code signal3 to completely get rid of my dependence on the
typedef. Once again, the only reason I want to do this is because I can
(hopefully)
Thanks