Nginx阅读: typedef定义函数指针类型
2013-08-30 11:16
447 查看
/*function point definition*/ typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len); struct ngx_log_s { ngx_uint_t log_level; ngx_open_file_t *file; ngx_atomic_uint_t connection; ngx_log_handler_pt handler; //function ptr definition void *data; /* * we declare "action" as "char *" because the actions are usually * the static strings and in the "u_char *" case we have to override * their types all the time */ char *action; ngx_log_t *next; };
此处ngx_log_handler_pt类型是对复杂函数指针的替代,使用起来更加方便,同时只要参数类型相同,ngx_log_handler_pt类型就可以指向并调用改函数,例如:
此例子源自:/article/7049487.html, 关于typedef与#define的讲解,挺赞!
#include <iostream> using namespace std; typedef int (*A) (char, char); int ss(char a, char b) { cout<<"in func ss()"<<endl; cout<<a<<endl; cout<<b<<endl; return 0; } int bb(char a, char b) { cout<<"in func bb()"<<endl; cout<<b<<endl; cout<<a<<endl; return 0; } int main() { A a; a = ss; a('a','b'); a = bb; a('a', 'b'); return 0; }
相关文章推荐
- typedef函数指针与函数类型的定义及使用方式
- typedef函数指针与函数类型的定义及使用方式
- (C++)用typedef定义函数指针类型
- 利用typedef定义函数指针类型
- C++用typedef定义函数指针类型typedef可以用于定义函数指针类型
- C++学习14:使用typedef定义函数指针类型
- C语言学习9: malloc动态内存存储,动态内存分配去空格字符增长版,动态内存分配去符号incr增长版,型参和返回值都是int型的函数的指针,main函数的地址也可以用指针指向,typedef定义函数指针,函数定义与嵌套的作用,返回函数指针类型,const作用
- 用typedef定义函数指针类型(转)
- C++------------typedef 函数指针类型定义
- C++------------typedef 函数指针类型定义
- typedef int (* func)(int ,int ) 定义函数指针类型 的理解
- GetProcAddress 省略转换(即省略typedef定义函数类型)
- 基类中定义的虚函数在派生类中重新定义时,其函数原型,包括返回类型、函数名、参数个数、参数类型及参数的先后顺序,都必须与基类中的原型完全相同 but------> 可以返回派生类对象的引用或指针
- 指向函数的指针类型定义
- typedef用于函数指针的定义
- 用typedef定义函数类型
- typedef定义函数指针
- 数组类型——typedef定义的数组类型的函数调用
- 预编译、类型定义、static、extern及函数指针
- 模板类中的成员函数定义返回值为类中的typedef类型时候注意