结构体C中“:”的含义是什么[重复]

2024-03-23

可能的重复:
“无符号温度:3”是什么意思 https://stackoverflow.com/questions/2950029/what-does-unsigned-temp3-means

  struct Test
  {
      unsigned a : 5;
      unsigned b : 2;
      unsigned c : 1;
      unsigned d : 5;
  };

  Test B;
  printf("%u %u %u %u", B.a, B.b, B.c, B.d); // output: 0 0 0 0
  static struct   Test A = { 1, 2, 3, 4};

有人可以解释一下目的是什么吗:指导,printf只是输出0所以我假设这些不是默认值,但它们是什么?

也有人可以解释一下为什么A.a, A.b, A.c, A.d输出1, 2, 1, 4代替1, 2, 3, 4


这是一个位域 http://en.wikipedia.org/wiki/Bit_field.

它基本上告诉编译器hey, this variable only needs to be x bits wide, so pack the rest of the fields in accordingly, OK?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

结构体C中“:”的含义是什么[重复] 的相关文章

随机推荐