结束后长的意思是什么? [英] the colon after the long is mean what?

查看:125
本文介绍了结束后长的意思是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct S2{//32
    long a1:2;
    long a2:30;
    LONG64 a;
};



长a1:2; 长冒之后的冒号是什么意思?


long a1:2; the colon after the long is mean what?

推荐答案

这是一个位字段(您可以使用Google获取更多信息和样本)。



基本上,这意味着2位是用于a1和30位用于a2。 64位用于a。这总共提供了96个可用位。对齐目的,实际大小可能更大。



通过位字段本身,它们通常会组合到一个int的大小,如果需要更多的位,将从下一个边界开始。此外,最大数量通常为32或64,具体取决于平台。



因此,一个位字段基本上可用于将类型拆分为多个位字段。因此可以在某些情况下用于减少内存使用,或者也可以简单地定义与somne​​硬件寄存器匹配的结构(在嵌入式软件中更常见)。
This is a bit field (You can use Google for more information and samples).

Essentially, it means that 2 bits are used for a1 and 30 bits for a2. 64 bits are used for a. This give a total of 96 usable bits. Actual size might be bigger for alignment purpose.

Fot the bit fields themselves, they will generally be combined up to the size of an int and if more bits are required, the will start on next boundary. Also, the maximum number of will usually be 32 or 64 depending on the platform.

Thus a bit field can essentially be used to split a type into multiple bit fields. Thus is can be used to reduce memory usage in some case or also simply to define a structure that matches somne hardware registers (more common in Embedded software).


这篇关于结束后长的意思是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆