小编use*_*887的帖子

嵌套结构填充 - C - 64 位 - linux

我在 C 中有以下嵌套结构。(64 位)

    typedef struct {
        int a;
        int b;
        int c;
        struct {
            int ab;
            long bc;
        }
        int d;
    } Test;

I see that,
a = 4 bytes
b = 4 bytes
c = 4 bytes
padding1 = 4 bytes 
inner structure = 16 bytes ( 4 bytes for ab, 4 bytes padding, 8 bytes for bc)
d = 4 bytes
padding2 = 4 bytes
Run Code Online (Sandbox Code Playgroud)

sizeof(Test) 返回 40 个字节。

我的问题:

  1. padding1 -> 为什么是 4 个字节?这是因为内部结构本身应该对齐吗?。(此外,它是否与 8 字节(长)或 …

c 64-bit nested structure padding

5
推荐指数
1
解决办法
3131
查看次数

标签 统计

64-bit ×1

c ×1

nested ×1

padding ×1

structure ×1