简体   繁体   English

如何理解函数的函数参数中的星号(*)?

[英]How to understand star sign(*) in function's function argument?

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 我不了解*continuation* *continuation*continuation的用途是什么

update 更新

The full code is in "/usr/include/sigsegv.h" in linux 完整的代码在Linux的“ /usr/include/sigsegv.h”中

update 更新

I use sigsegv_leave_handler like following: 我使用sigsegv_leave_handler如下所示:

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 ). 只是一个声明,其中continuation是指向使用3个void *指针且不返回任何内容( 带有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 有用的工具是C乱码↔英文

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 将sigsegv_leave_handler声明为extern函数(指向函数的指针(指向void的指针,指向void的指针,指向void的指针)返回void,指向void的指针,指向void的指针,指向void的指针)返回int

Or in other words, sigsegv_leave_handler() takes 4 arguments and returns an int . 换句话说, sigsegv_leave_handler()接受4个参数并返回一个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? *在* continuation中有什么用?

To show that the argument is a pointer to a function. 显示参数是指向函数的指针。

void (*continuation) (void*, void*, void*),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM