在阅读DirectWrite源代码时,我遇到了以下结构:

/// <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;
};

在每个成员声明之后,请注意奇怪的“:”。我将假定它是成员变量的默认初始化值。

我尝试搜索Google进行确认,但是却不知道到底叫什么(大多数结果都与默认初始化有关)。

此技术的名称是什么?

最佳答案



这不是默认的初始化。这意味着breakConditionBefore只是2位整数,isWhitespace1位整数。等等。

DWRITE_LINE_BREAKPOINT中,将一个8位整数(即UINT8)分配给5个成员,其中3个是2位整数,而2个成员是1位整数。

了解有关Bit-fields的信息

关于c++ - 结构成员初始化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5563861/

10-08 22:03
查看更多