Whilst reading through the DirectWrite source code I came across the following struct:
/// <summary>
/// Line breakpoint characteristics of a character.
/// </summary>
struct DWRITE_LINE_BREAKPOINT
{
/// <summary>
/// Breaking condition before the character.
/// </summary>
UINT8 breakConditionBefore : 2;
/// <summary>
/// Breaking condition after the character.
/// </summary>
UINT8 breakConditionAfter : 2;
/// <summary>
/// The character is some form of whitespace, which may be meaningful
/// for justification.
/// </summary>
UINT8 isWhitespace : 1;
/// <summary>
/// The character is a soft hyphen, often used to indicate hyphenation
/// points inside words.
/// </summary>
UINT8 isSoftHyphen : 1;
UINT8 padding : 2;
};
Notice the strange ” : ” after each member declaration. I’m going to assume it’s a default initialisation value for the member variable.
I tried searching Google to confirm, but without knowing exactly what it’s called I didn’t get far (most of the results where to do with default initialisation).
What is the name of this technique?
It’s not default initialization. It means
breakConditionBeforeis just2bit integer,isWhitespaceis a1bit integer. And so on.In
DWRITE_LINE_BREAKPOINT, one 8-bit integer (i.e UINT8) is divided amongst 5 members, 3 of which are 2-bit integers, and 2 members are 1-bit integers.Read about Bit-fields