void(* var_name)(data_type) - 此声明如何工作?

时间:2021-11-01 06:02:49

I am not able to understand how the above declaration work and where I can make its use .... I first encounterd this declaration while making use of signal.h file in c programming.

我无法理解上述声明是如何工作的以及我可以在哪里使用....我首先在c编程中使用signal.h文件时遇到了这个声明。

2 个解决方案

#1


2  

This is a function pointer decalaration

这是一个函数指针decalaration

void (*var_name)(int)

void(* var_name)(int)

In this example, var_name is a pointer to a function taking one argument, integer, and that returns void. It's as if you're declaring a function called "*var_name", which takes an int and returns void; now, if *var_name is a function, then var_name must be a pointer to a function

在此示例中,var_name是一个指向函数的指针,该函数采用一个参数integer,并返回void。这就好像你要声明一个名为“* var_name”的函数,它接受一个int并返回void;现在,如果* var_name是一个函数,则var_name必须是指向函数的指针

#2


0  

http://cyan-lang.org/jose/courses/06-2/lc/Ponteiros-para-Funcoes.htm

http://cyan-lang.org/jose/courses/06-2/lc/Ponteiros-para-Funcoes.htm

It's in Portuguese, Example:

它是葡萄牙语,例如:

in C, we can declare a pointer to function with the syntax

在C中,我们可以使用语法声明一个指向函数的指针

void (* f) ();

In this case, f is a pointer to a function with no parameters and that returns void. F can point to a compatible function:

在这种情况下,f是指向没有参数且返回void的函数的指针。 F可以指向兼容的功能:

F = maximum;

Maximum is a function declared as

Maximum是声明为的函数

void max () {
    Puts ("Hi, I'm the max");
}

Maximum can be called from f using any of the syntax below.

可以使用以下任何语法从f调用最大值。

(* F) (); / * Maximum call * /
F (); / * Maximum call * /

#1


2  

This is a function pointer decalaration

这是一个函数指针decalaration

void (*var_name)(int)

void(* var_name)(int)

In this example, var_name is a pointer to a function taking one argument, integer, and that returns void. It's as if you're declaring a function called "*var_name", which takes an int and returns void; now, if *var_name is a function, then var_name must be a pointer to a function

在此示例中,var_name是一个指向函数的指针,该函数采用一个参数integer,并返回void。这就好像你要声明一个名为“* var_name”的函数,它接受一个int并返回void;现在,如果* var_name是一个函数,则var_name必须是指向函数的指针

#2


0  

http://cyan-lang.org/jose/courses/06-2/lc/Ponteiros-para-Funcoes.htm

http://cyan-lang.org/jose/courses/06-2/lc/Ponteiros-para-Funcoes.htm

It's in Portuguese, Example:

它是葡萄牙语,例如:

in C, we can declare a pointer to function with the syntax

在C中,我们可以使用语法声明一个指向函数的指针

void (* f) ();

In this case, f is a pointer to a function with no parameters and that returns void. F can point to a compatible function:

在这种情况下,f是指向没有参数且返回void的函数的指针。 F可以指向兼容的功能:

F = maximum;

Maximum is a function declared as

Maximum是声明为的函数

void max () {
    Puts ("Hi, I'm the max");
}

Maximum can be called from f using any of the syntax below.

可以使用以下任何语法从f调用最大值。

(* F) (); / * Maximum call * /
F (); / * Maximum call * /