我知道 typedef 可以用来定义一个新的自定义类型,例如:
// simple typedef
typedef unsigned long ulong;
// the following two objects have the same type
unsigned long l1;
ulong l2;
我最近遇到了这个 typedef,并在破译声明中发生的事情时迷失了方向:
typedef int16_t CALL_CONVENTION(* product_init_t)(product_descript_t *const description)
有人可以指导我并解释这是在做什么吗?
编辑:将 NEW_TYPE 更改为 CALL_CONVENTION。这是一个定义。感谢您发现这一点。
最佳答案
它将类型 product_init_t
声明为指向函数的指针
- 接受参数
product_descript_t *const description
; - 返回
int16_t
; - 使用调用约定
CALL_CONVENTION
(正如 @M.M 建议的,即使它被错误命名)。
P.S. 因为“2016 年的完整答案应该展示编写此 type-alias
的现代方式”(@Howard Hinnant),这里是:
using product_init_t = int16_t (CALL_CONVENTION *)(product_descript_t *const description);
关于c++ - C++ 中复杂的 Typedef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37555429/