bit field padding in C

后端 未结 4 545
暗喜
暗喜 2021-02-10 15:06

Continuing my experiments in C, I wanted to see how bit fields are placed in memory. I\'m working on Intel 64 bit machine. Here is my piece of code:

#include <         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-10 15:55

    From the ISO C standard:

    An implementation may allocate any addressable storage unit large enough to hold a bit- field. (and later) There may be unnamed padding at the end of a structure or union.

    So there's no requirement to always choose the smallest possible chunk of memory for the struct. And since 32-bit words are probably the native size for your compiler, that's what it chooses.

提交回复
热议问题