使用libpq获取sizeof(PGconn)
我正在尝试为一个程序包装libpq,我正在使用的FFI工具的一部分尝试获取使用libpq获取sizeof(PGconn),c,postgresql,gcc,libpq,C,Postgresql,Gcc,Libpq,我正在尝试为一个程序包装libpq,我正在使用的FFI工具的一部分尝试获取sizeof()任何正在使用的结构。在这种情况下,问题是试图获取sizeof(PGconn)会导致来自GCC的一系列错误,因为它是一个不完整的类型。有没有办法获得相同的数据,或者我是否需要训练使用这个FFI工具来忽略那些想要不透明的类型?以下是生成的C代码和编译器错误供参考: /* Define on Darwin to activate all library features */ #define _DARWIN_C_
sizeof()
任何正在使用的结构。在这种情况下,问题是试图获取sizeof(PGconn)
会导致来自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;
}
当我在谷歌上搜索
PGConn
时,我看到的一切都是你在处理PGConn*
而不是PGConn
。我的猜测是,您应该通过指针将其作为不透明类型处理
但我确实找到了参考资料。也许这对你有帮助。当我在谷歌上搜索
PGConn
时,我看到的一切都是你在处理PGConn*
而不是PGConn
。我的猜测是,您应该通过指针将其作为不透明类型处理
但我确实找到了参考资料。也许这对你有帮助。
PGConn
在设计上是不透明的。如果需要查看,请包括libpq-int.h
(用于“内部”)。但是考虑重新考虑你的需求。<代码> PGConn <代码>是设计不透明的。如果需要查看,请包括
libpq-int.h
(用于“内部”)。但是考虑重新考虑你的需求。
[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’