c++ - typedef struct with undeclared/undefined type -


i reading webrtc source code vad, , confused code

typedef struct webrtcvadinst vadinst; 

i have searched code webrtcvadinst , did not find source related struct webrtcvadinst. on other hand, did find vadinst.

typedef struct vadinstt_ {     int vad;     int32_t downsampling_filter_states[4];     ...     ...     int init_flag; } vadinstt; 

and

vadinst* webrtcvad_create() {   vadinstt* self = (vadinstt*)malloc(sizeof(vadinstt));    webrtcspl_init();   self->init_flag = 0;    return (vadinst*)self; } 

and, compiles successfully.

how work?

the typedef combines forward declare , typedef in single line.

in c++ written

struct webrtcvadinst;            // forward declare struct  typedef webrtcvadinst vadinst;   // , introduce alternate name 

there no problem in either language form pointer unknown struct, pointers structs (and classes in c++) required have same size.

so code shown never uses struct (if exists) pointer (vadinst*). , that's ok language-wise.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -