Here is what I confused:
extern int sigsegv_leave_handler (
void (*continuation) (void*, void*, void*),
void* cont_arg1, void* cont_arg2, void* cont_arg3);
I don't understand *continuation
, what's the use for *
in *continuation
update
The full code is in "/usr/include/sigsegv.h" in linux
update
I use sigsegv_leave_handler
like following:
void cont(void *fault_addr, void *arg1, void *arg2) {
// rb_raise(rb_eTypeError, "type err");
rraise(SEGV, NULL);
}
int handle_segv(void *fault_addr, int serious) {
sigsegv_leave_handler(cont, fault_addr, NULL, NULL);
}
This
void (*continuation) (void*, void*, void*)
is simply a declaration where continuation
is a pointer to a function taking 3 void *
pointers and not returning anything ( with void
return type ).
This is how you declare pointers to functions,
RETURN_TYPE (*IDENTIFIER)(... PARAMETERS WITH THEIR TYPES AS USUAL ...);
A useful tool to use is C gibberish ↔ English
extern int sigsegv_leave_handler (void (*) (void*, void*, void*), void* , void* , void* );
declare sigsegv_leave_handler as extern function (pointer to function (pointer to void, pointer to void, pointer to void) returning void, pointer to void, pointer to void, pointer to void) returning int
Or in other words, sigsegv_leave_handler()
takes 4 arguments and returns an int
.
1) pointer to a function which takes 3 void * pointers and returns void
void (*f) (void*, void*, void*)
2) pointer to void
void *
3) pointer to void
void *
4) pointer to void
void *
what's the use for * in *continuation?
To show that the argument is a pointer to a function.
void (*continuation) (void*, void*, void*),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.