Never defined structure

后端 未结 2 1917
一整个雨季
一整个雨季 2021-02-13 20:20

Is there any benefit in having never-defined structures in C ?

Example in SQLite source code :

/* struct sqlite3_stmt is never defined */
typedef struct          


        
2条回答
  •  北海茫月
    2021-02-13 20:57

    It is defined like this to hide the implementation detail of sqlite3_stmt from the user, thus avoiding the internal states from being messed around. See Opaque pointer.

    (This also forces the user only to use the type as a pointer since the structure sqlite3_stmt itself has incomplete implementation.)


    Edit: VDBE (virtual database engine) is just "a" back-end of the SQLite3 API. I believe the back-end is changeable, thus a sqlite3_stmt* is not necessarily a Vdbe*. Not exposing Vdbe* in the API because the back-end detail should not be exposed.

提交回复
热议问题