具有未声明/未定义类型的 typedef 结构
typedef struct with undeclared/undefined type
我正在阅读有关VAD的webrtc源代码,我对代码感到困惑
typedef struct WebRtcVadInst VadInst;
我已经搜索了所有关于WebRtcVadInst的代码,没有找到任何与结构WebRtcVadInst相关的源代码。另一方面,我确实发现了一些关于VadInst的东西。
typedef struct VadInstT_ {
int vad;
int32_t downsampling_filter_states[4];
...
...
int init_flag;
} VadInstT;
和
VadInst* WebRtcVad_Create() {
VadInstT* self = (VadInstT*)malloc(sizeof(VadInstT));
WebRtcSpl_Init();
self->init_flag = 0;
return (VadInst*)self;
}
并且,它编译成功。
它是如何工作的?
typedef 在一行中组合了前向声明和 typedef。
在C++可以写
struct WebRtcVadInst; // forward declare a struct
typedef WebRtcVadInst VadInst; // and introduce an alternate name
在这两种语言中,形成指向未知结构的指针都没有问题,因为所有指向结构(和C++中的类(的指针都需要具有相同的大小。
因此,您显示的代码从不使用结构本身(如果它甚至存在(,而只使用指针(VadInst*)
。这在语言方面是可以的。
相关文章:
- 如何创建 typedef 结构的前向声明
- 无法转发声明C typedef结构-正在查找其他建议
- 如何使用 SWIG 接口访问 python 中的 C++ typedef'd 结构
- 具有未声明/未定义类型的 typedef 结构
- 在 CPP 中初始化 typedef 结构变量
- C++ 无法在 typedef 结构中重载<运算符
- 在 typedef 结构中声明一个数组
- 从 csv 文件中获取不同类型的数据,并将其放入 C++ 中的 typedef 结构中
- 为什么 typedef 结构允许默认初始值设定项?
- 为什么我不能像正常一样初始化 typedef 结构字符串或字符?
- 在Typedef结构中,下划线意味着什么
- 来自 typedef 结构的错误
- 在Typedef结构(C )中超载运算符
- C++中具有对象名称的typedef结构的正向声明
- 为什么Typedef结构会产生链路故障
- 在Typedef结构中定义结构
- 类中typedef结构的奇怪行为
- C/C++ 中的套接字编程 - 接收由 typedef 结构定义的消息
- 扩展typedef结构(与VC++11兼容)
- 为什么子类在C++中看不到父类的 typedef 结构?