在函数中
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*。
但是在这里,db是sqlite3*类型的,db->malloFailed怎么存在呢?为什么编译器没有抱怨呢?
sqlite3_stmt也有类似的情况
typedef struct sqlite3_stmt sqlite3_stmt;没有身体。我猜sqlite3_stmt是一个解析过的SQL语句的语法树。我想看看它的结构。然而,使用这种奇怪的模式将类型隐藏得如此之深,以至于我看不出它是什么。
即使是Vdbe也是一样的情况。
typedef struct Vdbe Vdbe;真正的struct到底在哪里?
发布于 2013-02-05 15:56:37
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 */
...https://stackoverflow.com/questions/14701298
复制相似问题