返回信息流☆─────────────────────────────────────☆
merrylife (Delia) 于 (Tue Jan 8 18:05:13 2008) 提到:
请问:
typedef void (*ILibWebServer_Session_OnSendOK)(struct ILibWebServer_Session *sender);
是什么意思,能解释一下吗,谢谢?
☆─────────────────────────────────────☆
sunway (sunway) 于 (Tue Jan 8 18:13:06 2008) 提到:
ILibWebServer_Session_OnSendOk is a pointer to a function which takes a pointer to a struct ILibWebServer_Session as parameter and returning void
参考 expert C programming
【 在 merrylife (Delia) 的大作中提到: 】
: 标 题: 关于typedef
: 发信站: 北邮人论坛 (Tue Jan 8 18:05:13 2008), 站内
:
: 请问:
: typedef void (*ILibWebServer_Session_OnSendOK)(struct ILibWebServer_Session *sender);
: 是什么意思,能解释一下吗,谢谢?
: --
:
: ※ 来源:·北邮人论坛 http://forum.byr.edu.cn·[FROM: 220.231.15.*]
☆─────────────────────────────────────☆
xt850109 (如水生活) 于 (Tue Jan 8 18:34:57 2008) 提到:
是函数指针,指向的函数有一个结构型的参数
☆─────────────────────────────────────☆
yywbupt (Fighting dreamers) 于 (Tue Jan 8 19:45:22 2008) 提到:
【 在 sunway 的大作中提到: 】
: ILibWebServer_Session_OnSendOk is a pointer to a function which takes a pointer to a struct ILibWebServer_Session as parameter and returning void
: 参考 expert C programming
:
说得不太准确,请注意这个帖子的主题......前面没有typedef它确实是个pointer,有typedef它就是个类型的别名了
比如
typedef int (*F)(int a);//F是int(int) *这个类型的别名,这句可以看成typedef ( int(int) *) F
F func; //这儿func才是一个pointer
☆─────────────────────────────────────☆
ny (ttmdy) 于 (Mon Jan 14 11:12:24 2008) 提到:
恩
【 在 sunway 的大作中提到: 】
: ILibWebServer_Session_OnSendOk is a pointer to a function which takes a pointer to a struct ILibWebServer_Session as parameter and returning void
: 参考 expert C programming
:
☆─────────────────────────────────────☆
xiaobin (ooxx) 于 (Mon Jan 14 19:47:43 2008) 提到:
这么解释是比较正确的
【 在 yywbupt 的大作中提到: 】
: 说得不太准确,请注意这个帖子的主题......前面没有typedef它确实是个pointer,有typedef它就是个类型的别名了
: 比如
: typedef int (*F)(int a);//F是int(int) *这个类型的别名,这句可以看成typedef ( int(int) *) F
: ...................
☆─────────────────────────────────────☆
merrylife (Delia) 于 (Tue Jan 15 13:58:01 2008) 提到:
那
typedef void * GetLock;
又是什么意思呢?
如果这么定义:
void * GetLock; //应该等同于:typedef void * GetLock
是不是指GetLock可以指向任何类型的指针,不管是变量,函数还是结构?
【 在 yywbupt 的大作中提到: 】
: 说得不太准确,请注意这个帖子的主题......前面没有typedef它确实是个pointer,有typedef它就是个类型的别名了
: 比如
: typedef int (*F)(int a);//F是int(int) *这个类型的别名,这句可以看成typedef ( int(int) *) F
: ...................
☆─────────────────────────────────────☆
rebirthatsix (茫犭者) 于 (Tue Jan 15 15:17:04 2008) 提到:
typedef,typedef
顾名思义,其是为了定义一个类型的别名
而你直接写void * getlock
这定义的是一个变量
类型和变量可要分清楚阿
☆─────────────────────────────────────☆
difuk (胖夫||The world) 于 (Tue Jan 15 15:22:11 2008) 提到:
【 在 merrylife 的大作中提到: 】
: 那
: typedef void * GetLock;
: 又是什么意思呢?
: ...................
god please
" typedef oldType newType; "
then you can use "newType" to define variable you want
if you want have an int variable 5,
you can simply type " int num=5; "
or
" typedef int MyInt; " and " MyInt num=5; "
that is it.
☆─────────────────────────────────────☆
yegle (奇峰怪石,秀山丽水) 于 (Tue Jan 15 15:26:14 2008) 提到:
问个小问题
typedef int MyInt
和
#define MyInt int
有什么区别?
【 在 difuk (胖夫||The world) 的大作中提到: 】
: god please
: " typedef oldType newType; "
: then you can use "newType" to define variable you want
: ...................
☆─────────────────────────────────────☆
Xer (Benogy) 于 (Tue Jan 15 15:39:41 2008) 提到:
你的例子没区别,但是推荐用typedef。你可以比较一下下面这个例子:
typedef char* charPtr;
#define charPtr char*
【 在 yegle (奇峰怪石,秀山丽水) 的大作中提到: 】
: 问个小问题
: typedef int MyInt
: 和
: ...................
☆─────────────────────────────────────☆
merrylife (Delia) 于 (Tue Jan 15 16:00:30 2008) 提到:
1:用typedef int MyInt
编译的时候会作类型检查。
而#define MyInt int只是简单的替换,编译时不做类型检查,存在安全隐患。
2:typedef 有作用域,在一个函数中typedef定义的函数外不能使用。
#define只要一定义就能通篇使用
3:功能不一样,#define只是简单的替换,typedef是类型定义
比如:
typedef int * MyInt;
MyInt a,b;//a,b都是int * 类型
#define MyInt int *
MyInt a,b;//则只有a是int *类型的,b为int 类型
【 在 yegle 的大作中提到: 】
: 问个小问题
: typedef int MyInt
: 和
: ...................
☆─────────────────────────────────────☆
yegle (奇峰怪石,秀山丽水) 于 (Tue Jan 15 16:15:43 2008) 提到:
赞!详细~
【 在 merrylife (Delia) 的大作中提到: 】
: 1:用typedef int MyInt
: 编译的时候会作类型检查。
: 而#define MyInt int只是简单的替换,编译时不做类型检查,存在安全隐患。
: ...................
☆─────────────────────────────────────☆
difuk (胖夫||The world) 于 (Tue Jan 15 16:17:05 2008) 提到:
【 在 merrylife 的大作中提到: 】
: 1:用typedef int MyInt
: 编译的时候会作类型检查。
: 而#define MyInt int只是简单的替换,编译时不做类型检查,存在安全隐患。
: ...................
我觉得你突然就赞起来了!
☆─────────────────────────────────────☆
merrylife (Delia) 于 (Tue Jan 15 16:20:29 2008) 提到:
我想起了以前问过的问题,有这例子:
typedef void (* MyFunction)(int address,char name);
那么这里MyFunction 类型可以用来定义其他变量,比如:
MyFunction YourFunction;//这里相当于:void YourFunction(int address,char name);
而#define 就不能这么做
☆─────────────────────────────────────☆
luckyboy (北邮人) 于 (Wed Jan 16 21:09:23 2008) 提到:
很好阿!
【 在 merrylife 的大作中提到: 】
: 1:用typedef int MyInt
: 编译的时候会作类型检查。
: 而#define MyInt int只是简单的替换,编译时不做类型检查,存在安全隐患。
: ...................
这是一条镜像帖。来源:北邮人论坛 / soft-design / #24023同步于 2008/1/24
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖
[合集] 关于typedef
CNLAS
2008/1/24镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。