Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICONTAINEROF 宏定义的疑惑 #54

Closed
QXSoftware opened this issue Feb 1, 2017 · 0 comments
Closed

ICONTAINEROF 宏定义的疑惑 #54

QXSoftware opened this issue Feb 1, 2017 · 0 comments

Comments

@QXSoftware
Copy link
Contributor

QXSoftware commented Feb 1, 2017

大神您好!我研读您的 kcp 协议代码,发现一处地方不太明白,具体是 ikcp.h 的 156~157 行。如下:

#define ICONTAINEROF(ptr, type, member) ( \
	(type*)( ((char*)((type*)ptr)) - IOFFSETOF(type, member)) )

这里 ptr 是指向 member 的指针,而 type 是包含 member 成员的父结构类型,所以 (char*)((type*)ptr) 这个强制转换为 type* 的过程感觉有点儿奇怪,感觉有点儿多余。不知是否有什么特殊的技巧还是纯粹多写了一个强制转换?

This was referenced Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant