English 中文(简体)
参照领域诉中定义
原标题:bit fields vs. stdint definitions

因此,我正在C++编制方案,而且只要我能告诉我们,C++就等于 st。 没有任何问题,因为你只能看一看一看一看一看一看一看一看一看一看,一看一看一看一看,一看一看一看一看一看,一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看一看一看一看一看,一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一

这两种法典的区别在于:

struct FREQ{
    unsigned int FREQLOHI :16;
    //etc...

};

and

struct FREQ{
    uint16_t FREQLOHI;
    //etc...
}

除了对借方的明显限制外,是否还有绩效/可流动问题? 哪一个选择?

最佳回答

差异在于,unsign int may be of different range on different prisons,而uint16_t is guarantee to have 16 bitidth. 这意味着第一个(轨道)结构的例子在不同平台上可能具有不同的规模。 而且,借用地比较昂贵,因为它涉及额外的转移和掩饰。

For example on laptop where unsigned int is 32-bit wide the first struct is 32-bit wide while the second struct is 16-bit.

就可运输性而言,借方领域处于更清洁的状态,因为它是旧的C语文特征,在1998年标准化时列入C++(ISO/IEC 14882:1998)。 另一方面,到1999年才在C部分添加了<代码>stdint.h(ISO/IEC 9899:1999 standard),因此不属于C++98(ISO/IEC 14882:1998)。 相应的标题<代码>cstdint 然后并入C++ TR1,但将所有识别资料列入<代码>std:tr1。 面包店也向导师提供。 最新的C++标准(C++11 akaISO/IEC 14882:2011,于2011年9月推出)包括标题<代码>cstdint,并将所有识别资料输入<>td。 尽管如此,<代码>cstdint仍得到广泛支持。

问题回答

编织者一般倾向于用单一字包装借方,从而减少其结构的整体规模。 这种包装损害了对借方成员的较慢准入。 例如:

struct Bitfields
{
    unsigned int eight_bit : 8;
    unsigned int sixteen_bit : 16;
    unsigned int eight_bit_2 : 8;
};

包装

0            8                        24
-----------------------------------------------------
| eight_bit  | sixteen_bit            | eight_bit_2 |
-----------------------------------------------------

每次访问<条码>,有十六条轨道,有变动和双向及操作。

另一方面,如果是,

struct NonBitfields
{
    uint8_t eight_bit;
    uint16_t sixteen_bit;
    uint8_t eight_bit_2;
};

因此,汇编者一般按字面对成员进行调和,并作如下表述:

0            8           16           24
-----------------------------------------------------
| eight_bit  |            | sixteen_bit             |
-----------------------------------------------------
| eight_bit_2|                                      |
-----------------------------------------------------

这些废物的面积比环绕区长得多,但成员可以更快地进入,而不必进行轨道转移和掩饰。


这里还有其他一些差异:

  • You can t apply sizeof to a bitfield member.
  • You can t pass a bitfield member by reference.

在可携带性方面,这两种备选办法都应致力于任何符合标准的汇编者。 如果你说,不同平台在撰写文件或书状时,具有双双向可移动性,那么,这两种情况都会发生。


就优惠而言,我将选择使用<代码>uint16_t<>/code>,而不是借方,除非有很好的理由将田地集中起来,以挽救空间。 如果我有许多“<条码>bool,则我通常使用借方,以同样的措辞压缩这些蓝 flag旗。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签