我正在阅读关于VAD的webrtc源代码,并且对代码感到困惑。
typedef struct WebRtcVadInst VadInst;我搜索了关于 WebRtcVadInst 的所有代码,没有找到任何与struct 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;
}而且,它成功地编译。
它怎麽工作?
发布于 2017-08-20 12:43:16
Ty胡枝子f在一行中组合了一个前向声明和一个ty胡枝子。
在C++中,可以编写
struct WebRtcVadInst; // forward declare a struct
typedef WebRtcVadInst VadInst; // and introduce an alternate name在这两种语言中,形成指向未知结构的指针没有问题,因为指向结构(以及C++中的类)的所有指针都必须具有相同的大小。
因此,您显示的代码从不使用结构本身(如果它甚至存在的话),而只使用指针(VadInst*)。就语言而言,这是可以的。
https://stackoverflow.com/questions/45781910
复制相似问题