- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为程序包装 libpq,并且我正在使用的 FFI 工具的一部分尝试获取正在使用的任何结构 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;
}
错误:
[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’
最佳答案
PGConn
在设计上是不透明的。如果您需要查看它,请包含 libpq-int.h
(对于“内部”)。但请考虑重新考虑您的要求。
关于c - 使用 libpq 获取 sizeof(PGconn),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4532227/
这个问题已经有答案了: Why isn't sizeof for a struct equal to the sum of sizeof of each member? (13 个回答) 已关闭 8
先生。 Stroustrup 在他的新书(TCPL 第 4 版)第 149 页写下了以下内容 1 N && sizeof(long)<=N任何 N 值的实现,更不用说任何人都会考虑使用 wchar_t
如 [5.3.3/3] 所述(expr.sizeof,工作草案): The sizeof operator can be applied to a pointer to a function, but
从C标准来看,int至少有16bit,long至少有32bit,long long如果有的话至少有64bit(有些平台可能不支持)。只是想知道标题中的句子是否总是正确的。 最佳答案 没有。该标准仅定义
我运行的是 Windows 7(64 位)。 这个问题与此处找到的问题相同: long on a 64 bit machine 但更深入,因为它处理更多的数据类型并适用到 C 或 C++,而不是 C#
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 8年前关闭。 Improve this
这个问题在这里已经有了答案: Length of array in function argument (9 个回答) 关闭 9 年前。 #include void printS(char []);
我承认这三个都有不同的含义。但是,我不明白这些具体情况适用于哪些特定情况。任何人都可以分享每个例子吗?谢谢。 malloc(sizeof(int)) malloc(size
To avoid things quietly breaking if you change the array size, I suggest std::copy(a, a + sizeof(a)/
我在 python 中注意到以下事实: >>> (1, 2, 3).__sizeof__() 48 >>> [1, 2, 3].__sizeof__() 64 我理解列表和元组之间的区别,但我希望它们
是否存在与指针大小相同的整数类型?保证所有微架构? 最佳答案 根据 this Wikipedia page ,在 C99 中,您的 stdint.h header 可能声明了 intptr_t 和 u
我注意到 int 和 double 的大小与使用函数 MPI_Type_size(MPI_INT, &MPI_INT_SIZE); 计算的不同。这是否意味着 sizeof(MPI_INT) 返回了错误
这个问题已经有答案了: How to find the size of an array (from a pointer pointing to the first element array)? (
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
为什么 sizeof 运算符返回的结构大小大于该结构成员的总大小? 最佳答案 这是因为添加了填充以满足对齐约束。 Data structure alignment影响程序的性能和正确性: 未对齐的访问
我是一名优秀的程序员,十分优秀!