Project

General

Profile

Bug #55389

Updated by Ilya Dryomov about 2 years ago

<pre> 
   union { 
     uint8_t flags; 
     uint8_t flags = 0; 
     struct { 
       uint8_t entry_valid :1; /* if 0, this entry is free */ 
       uint8_t sync_point :1;    /* No data. No write sequence number. Marks sync 
                                  point for this sync gen number */ 
       uint8_t sequenced :1;     /* write sequence number is valid */ 
       uint8_t has_data :1;      /* write_data field is valid (else ignore) */ 
       uint8_t discard :1;       /* has_data will be 0 if this is a discard */ 
       uint8_t writesame :1;     /* ws_datalen indicates length of data at write_bytes */ 
     }; 
   }; 
 </pre> 

 <pre> 
   DENC(WriteLogCacheEntry, v, p) { 
     DENC_START(1, 1, p); 
     ...  
     denc(v.flags, p); 
     ... 
     DENC_FINISH(p); 
   } 
 </pre> 

 Bit fields are not suit for anything where layout actually matters.    Here, depending on the platform and the compiler, entry_valid can refer to either least significant bit of flags or the most significant bit: 

 > <pre> 
 An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined. The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined. The alignment of the addressable storage unit is unspecified. 
 </pre>

Back