bit field padding in C

后端 未结 4 549
暗喜
暗喜 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:44

    Even though the total requirement is just 2 Bytes (1+3+4+1+3+2+2) in this case, the size of the data type used (unsigned int) is 4 bytes. So the allocated memory is also 4 Bytes. If you want just 2 Bytes allocated use unsigned short as your data type and run the program again.

提交回复
热议问题