プログラムのlibpqをラップしようとしていますがsizeof()
、使用中の構造体を取得しようとしているFFIツールの一部です。この場合の問題は、sizeof(PGconn)
GCC が不完全な型であるため、結果を取得しようとすると GCC から一連のエラーが発生することです。同じデータを取得する方法はありますか、またはこの FFI ツールをトレーニングして、不透明であることを意図した型を無視する必要がありますか? 参考までに、生成された C コードとコンパイラ エラーを次に示します。
/* Define on Darwin to activate all library features */
#define _DARWIN_C_SOURCE 1
/* This must be set to 64 on some systems to enable large file support. */
#define _FILE_OFFSET_BITS 64
/* Define on Linux to activate all library features */
#define _GNU_SOURCE 1
/* This must be defined on some systems to enable large file support. */
#define _LARGEFILE_SOURCE 1
/* Define on NetBSD to activate all library features */
#define _NETBSD_SOURCE 1
/* Define to activate features from IEEE Stds 1003.1-2001 */
#define _POSIX_C_SOURCE 200112L
/* Define on FreeBSD to activate all library features */
#define __BSD_VISIBLE 1
#define __XSI_VISIBLE 700
/* Windows: winsock/winsock2 mess */
#define WIN32_LEAN_AND_MEAN
#include <libpq-fe.h>
#include <stdio.h>
#include <stddef.h> /* for offsetof() */
void dump(char* key, int value) {
printf("%s: %d\n", key, value);
}
void dump_section_PGconn(void) {
typedef PGconn platcheck_t;
typedef struct {
char c;
platcheck_t s;
} platcheck2_t;
platcheck_t s;
dump("align", offsetof(platcheck2_t, s));
dump("size", sizeof(platcheck_t));
}
int main(int argc, char *argv[]) {
printf("-+- PGconn\n");
dump_section_PGconn();
printf("---\n");
return 0;
}
そしてエラー:
[platform:execute] gcc -c -O3 -pthread -fomit-frame-pointer -Wall -Wno-unused -I/usr/include/postgresql/ /tmp/usession-default-52/platcheck_10.c -o /tmp/usession-default-52/platcheck_10.o
[platform:Error] /tmp/usession-default-52/platcheck_10.c: In function ‘dump_section_PGconn’:
[platform:Error] /tmp/usession-default-52/platcheck_10.c:34: error: field ‘s’ has incomplete type
[platform:Error] /tmp/usession-default-52/platcheck_10.c:37: error: storage size of ‘s’ isn’t known
[platform:Error] /tmp/usession-default-52/platcheck_10.c:39: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’