• 已解决 73482 个问题
  • 已帮助 5993 位优秀工程师

终于找到Method的定义,哪个大神给解释下

sgf201 2018-05-23 浏览量:700
/**
 * Method declaration/definition macro providing private and public interface.
 *
 * Defines a method name with this as first parameter and a return value ret
 * and an alias for this method with a _ prefix having the this argument
 * safely casted to the public interface iface.
 * _name is provided a function pointer but will get optimized out by GCC.
 */
#define METHOD(iface name ret this ...) \
static ret name(union {iface *_public; this;} \
__attribute__((transparent_union)) ##__VA_ARGS__); \
static typeof(name) *_##name = (typeof(name)*)name; \
static ret name(this ##__VA_ARGS__)

以上是Method的宏定义 ,以下是个真实的方法定义,来个大神给分析下

METHOD(private_key_t get_type key_type_t
private_openssl_rsa_private_key_t *this)
{
return KEY_RSA;
}

我把上面的宏替换了,大牛给解释下这儿的三句都实现了个啥功能吧

static key_type_t get_type (union {private_key_t *_public; this;} \
__attribute__((transparent_union)) ); \
static typeof(name) *_get_type  = (typeof(get_type )*)get_type ; \
static key_type_t  get_type (this )


0 0 收起

我来回答

上传资料:
选择文件 文件大小不超过15M(格式支持:doc、ppt、xls、pdf、zip、rar、txt)
所有亮答 数量:1
  • 和编译器相关的太多了,连接符,属性设置,建议跟下代码把替换的部分替换掉看看最终的形式
sgf201 回复了 skawu:我已替换,见问题,主要 是这里边的三句实现了个啥帮忙分析下 回复

相关问题

问题达人换一批

终于找到Method的定义,哪个大神给解释下