Unable to save a float value to a bitfield structure

后端 未结 5 1813
时光说笑
时光说笑 2020-12-18 11:16

I have a structure

struct {
   u32 var1 :7;
   u32 var2 :4;
   u32 var3 :4;
   u32 var4 :1;
   u32 var5 :4;
   u32 var6 :7;
   u32 var7 :4;
   u32 var8 :1;
          


        
5条回答
  •  醉酒成梦
    2020-12-18 11:54

    You cannot store a float value in a bit-field structure. Floats have to adhere to a specific standard (IEEE 754) that specifies a representation. These representations are for 32 and 64 bits on x86. Therefore a bit field wouldn't have the necessary space to properly represent a floating point value..

    Bit-fields muse be a signed or unsigned integer.

提交回复
热议问题