【发布时间】:2018-07-11 09:55:05
【问题描述】:
假设我有 2 个结构:
struct Foo
{
int size; // 4
int type; // 4
char data; // 1
};
static const struct Foo FooContainer[] = {
{1, 2, 3},
{4, 5, 6},
...
};
如果我使用类似的东西:
int structsincontainer = sizeof(FooContainer) / sizeof(struct Foo);
我总是能在容器中获得正确数量的结构吗?我假设由于填充已经在 struct Foos 中完成,容器不需要任何填充?
【问题讨论】:
-
"假设我有 2 个结构:" 你没有。您有 1 个结构和一个结构数组。不是“包含结构的结构”。