typedef 函数在 C 语言中的用法
typedef function usage in C
我正在尝试调用以下函数,但我不知道如何填写第三个参数。
RSA* PEM_read_RSAPrivateKey(FILE *fp, RSA **x, pem_password_cb *cb, void *u);
抬头pem_password_cb我发现:
typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
我理解带有函数指针的 typedefs,但这似乎不是函数指针。谁能帮我举个例子来说明第三个参数中的内容?我无法访问pem_password_cb的实施。
你是对的:这是函数类型的 typedef,而不是指针。但是该函数PEM_read_RSAPrivateKey
接收指向它的指针:pem_password_cb *cb
。
用法就像任何其他函数指针一样:
int some_func(char *buf, int size, int rwflag, void *userdata) {
return 0;
}
PEM_read_RSAPrivateKey(NULL, NULL, some_func, NULL);
/* Your function definition is like this. */
int my_pem_password_cb_fun(char *buf, int size, int rwflag, void *userdata)
{
/* your stuff */
}
将my_pem_password_cb_fun作为第三个参数传递。
pem_password_cb只是一个typedef,它不是实现。你需要实现一个函数 [my_pem_password_cb_fun((] 来接受 typedef 中给定的参数。
它是一个函数的typedef。
但请注意,pem_password_cb *cb
参数是一个指针。所以这个参数实际上是一个函数指针。
因此,您只需要实现一个与int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
签名匹配的函数。
相关文章:
- 这个指针在c++中的用法
- 不同语言中相同代码的不同行为
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- 当C++中需要自动删除时,这是静态的正确用法吗?
- r语言 - C++ 类型为"const std ::?
- 通用C++/Python 多语言的存在
- libstdc++ 文件系统中未初始化的用法?
- 复制和交换习惯用法与移动操作之间的交互
- 类作用域的类型别名"using":[何时]方法中的用法可以先于类型别名?
- 命名参数习惯用法和(抽象)基类
- 为什么我的 EnumWindowProc 不能用 C 语言编译?
- 了解算法的性能差异(如果以不同的编程语言实现)
- Rextester 语言编译C++问题
- 省略号在C++中的所有用法
- () 在 C++ 11 中的特殊而奇怪的用法?
- 如何将多种语言设置放在单个 .clang 格式文件中
- 不同语言中的模运算符差异
- typedef 函数在 C 语言中的用法
- 在 C 语言中 &(AND) 运算符的用法是什么?
- r语言 - 用NumericVector填充c++数组的更好的习惯用法