_int64位字段 [英] _int64 bit field

查看:145
本文介绍了_int64位字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在结构中使用6字节(48位)的位域,该结构可以用作无符号整数来进行比较等.

I need to use a 6-byte (48-bit) bitfield in a structure that I can use as unsigned integer for comparison etc. Something along the following:

pack (1)
struct my_struct {
  _int64 var1:48;
} s;

if (s.var >= 0xaabbccddee) { // do something }

但是以某种方式在64位Windows上,sizeof此结构始终返回8个字节,而不是6个字节.任何指针都值得赞赏吗?

But somehow on 64-bit Windows, sizeof this struct always returns 8 bytes instead of 6 bytes. Any pointers are appreciated?

推荐答案

您已使用_int64,因此sizeof返回8.这就像您已决定在可用的64位中使用48位一样.即使我们声明这样的东西-

You have used _int64 and hence sizeof returns 8. Its like you've decided to use up 48 bits out of the available 64 bits. Even if we declare something like this-

struct my_struct {
  _int64 var1:1;
} s;

仍然sizeof表示8.简而言之,将根据位域的类型分配位域.在这种情况下,它的_int64分配为8个字节.

Still sizeof would say 8. In short, allocation of bitfields would take place according to the type of the bitfield. In this case its _int64 and hence 8 bytes allocation.

这篇关于_int64位字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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