Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何使用函数的typedef?_C_Typedef - Fatal编程技术网

C 如何使用函数的typedef?

C 如何使用函数的typedef?,c,typedef,C,Typedef,这是什么意思? 如何定义变量,例如key_equiv_fn*equiv 您可以将函数指针与typedef一起使用,如下所示,我提供了代码作为示例: typedef bool key_equiv_fn(key x, key y); typedef int key_hash_fn(key x); #包括 例如,typedef struct_key/*就是一个例子*/ { char-keyy[24]; 内伦; }钥匙; int key_equiv_fn(key x,key y)/*函数定义*/ {

这是什么意思?
如何定义变量,例如
key_equiv_fn*equiv

您可以将函数指针与typedef一起使用,如下所示,我提供了代码作为示例:

typedef bool key_equiv_fn(key x, key y);
typedef int key_hash_fn(key x);
#包括
例如,typedef struct_key/*就是一个例子*/
{
char-keyy[24];
内伦;
}钥匙;
int key_equiv_fn(key x,key y)/*函数定义*/
{
printf(“你好”);
返回0;
}
typedef int(key_equiv_fn_ptrType)(key,key)/*声明函数指针*/
int main()
{
密钥等价于fn类型*ptr;
ptr=key_equiv_fn;/*将key_equiv_fn地址分配给函数指针ptr*/
键xx;
yy键;
xx.len=16;
ptr(xx,yy);/*使用指针ptr调用函数键*/
返回0;
}
这是什么意思

让我们看看:

#include<stdio.h>
typedef struct _key/*For example*/
{
char keyy[24];
int len;
}key;

int key_equiv_fn(key x,key y) /*Function defination*/
{
 printf("Hello");
return 0;
}

typedef int (key_equiv_fn_ptrType)(key,key); /*Declare function pointer */

int main()
{
key_equiv_fn_ptrType *ptr;
ptr = key_equiv_fn;/*assign key_equiv_fn address to function pointer ptr*/
 key xx;
 key yy;
xx.len = 16;
ptr(xx,yy);/*Call function key_equiv_fn using pointer ptr*/
return 0;
}
如何定义变量,例如
key_equiv_fn*equiv

#包括
typedef int键;
类型定义布尔键(键x,键y);
//创建一个我们将分配给指针的函数
布尔等于(键x,键y){return x==y;}
int main(){
键_equiv_fn*您的_指针;
您的指针=are_equal;//将are_equal地址分配给指针
bool equal=您的_指针(4,2);//调用函数
返回0;
}
typedef bool key_equiv_fn(key x, key y);
          ^         ^ 
       return  name of the    ^      ^
       value   *pointer type* arguments of the functions
               of the         both of type 'key'
               function
#include <stdbool.h>
typedef int key;
typedef bool key_equiv_fn(key x, key y);

// Create a function we will assign to the pointer

bool are_equal(key x, key y) { return x == y; }

int main() {
  key_equiv_fn *your_pointer;
  your_pointer = are_equal;        // assign are_equal address to the pointer
  bool equal = your_pointer(4, 2); // call the function
  return 0;
}