定義のない構造体
SQLiteを読んでるとsqlite3_stmtという構造体が名前だけ出てきます。ところが定義がどこを探してもありません。どうやらsqlite3_stmt*のような構造体はvoid*のように使えるようです。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> typedef struct Str Str; int main(void) { char str[] = "hello"; Str* p = (Str*)malloc(sizeof str); memset(p, 0, sizeof(str)); memcpy(p, str, sizeof(str)); assert(!strcmp((char*)p, str)); printf("%s\n",(char*)p); return 0; }
struct Strの定義はどこにも無いですが、コンパイルも通るし、動作もします。