结构填充说明

时间:2016-08-22 11:39:03

标签: c data-structures structure sizeof

我知道abc中的填充如下所示

struct abc {
  char a;
  int b;
  char c;
}a;

上述结构中的填充是

struct abc{
    char a;
    pad[3];
    int b;
    char c;
    pad[3];
}a;

请告诉我们如何在struct xyz中完成填充

struct xyz{
  int x;
  char y;
  char z;
}x;

编译器在哪里放置y和z?为什么?

1 个答案:

答案 0 :(得分:2)

填充不是通用的,因为它是实现定义的:不同的系统可能选择以不同的方式进行。

相关问题