c

  • 22nd February 2026

Bit-field layout

The C and C++ standards leave nearly every detail to the implementation. C23 §6.7.3.2:

An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined. The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined. The alignment of the addressable storage unit is unspecified

C++ is also terse — [class.bit]p1:

Allocation of bit-fields within a class object is implementation-defined. Alignment of bit-fields is implementation-defined. Bit-fields are packed into some addressable allocation unit.

…

Read more →
  • 14th March 2015

调试技巧2

之前写过一篇《Debug Hacks》和调试技巧。

CFLAGS使用-g3

对于重度使用macro的程序很有用,可以在gdb里使用info macro NAME、macro expand EXPR等命令了,print参数里的macro也可以展开。

…

Read more →
  • 25th July 2013

《Debug Hacks》和调试技巧

下篇见调试技巧2。

Debug Hacks

作者为吉冈弘隆、大和一洋、大岩尚宏、安部东洋、吉田俊辅,有中文版《Debug Hacks中文版—深入调试的技术和工具》。这本书涉及了很多调试技巧,对调试器使用、内核调试方法、常见错误的原因,还介绍了systemtap、strace、ltrace等一大堆工具,非常值得一读。

…

Read more →