【问题标题】:Union/Structure datatype and bit field referencing speed联合/结构数据类型和位域引用速度
【发布时间】:2012-02-20 19:56:54
【问题描述】:

使用下面的union typedef,访问MyPacket.Byte.LB和访问MyPacket.Field.LB的速度有区别吗?

typedef union       // create a union to assemble bytes into ints
{
int Packet;     //  contains an int
struct
    {
    char HB;
    char LB;    
    }Byte;
struct
    {
    unsigned    field1:4;
    unsigned    field2:2;
    unsigned    field3:1;
    unsigned    field4:1;
    unsigned    LB:8;
    }Field;
} packetunion;

packetunion MyPacket;

【问题讨论】:

    标签: c struct bit-fields unions


    【解决方案1】:

    确定的唯一方法是编写两个版本的代码并在目标系统上对它们进行分析,以进行多个编译器优化设置。如果您看到可测量的差异,我会感到非常惊讶。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多