在sqlite3源代码中混淆sqlite3结构

在function

static int sqlite3Prepare( sqlite3 *db, /* Database handle. */ const char *zSql, /* UTF-8 encoded SQL statement. */ int nBytes, /* Length of zSql in bytes. */ int saveSqlFlag, /* True to copy SQL text into the sqlite3_stmt */ Vdbe *pReprepare, /* VM being reprepared */ sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ const char **pzTail /* OUT: End of parsed string */ ) { ... pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); ... assert( !db->mallocFailed ); ... } 

我知道sqlite3只是一个伪结构声明为

  typedef struct sqlite3 sqlite3; 

没有任何身体。 我知道sqlite3 *通常被Vdbe*转换为Vdbe*

但是在这里, dbsqlite3*的类型, db->malloFailed如何存在? 编译器为什么不抱怨?

sqlite3_stmt也有类似的情况:

 typedef struct sqlite3_stmt sqlite3_stmt; 

没有身体。 我猜sqlite3_stmt是解析过的SQL语句的语法树。 我想看看它的结构。 然而,使用这种奇怪的模式隐藏了这种类型,我无法看到它是什么。

甚至Vdbe也是同样的情况……

 typedef struct Vdbe Vdbe; 

真正的struct在哪里?

sqlite3 不是假结构; sqlite.h文件只是没有定义它的主体。

它的定义是在sqliteInt.h文件中(它也是sqlite3.c合并的一部分):

 /* ** Each database connection is an instance of the following structure. */ struct sqlite3 { sqlite3_vfs *pVfs; /* OS Interface */ struct Vdbe *pVdbe; /* List of active virtual machines */ CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ ... u8 mallocFailed; /* True if we have seen a malloc failure */ ...