You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use of bitfields is discouraged by many coding standards (including GSFC) because the C standard does not specifically dictate how they are packed into the underlying integer type. CF uses them in several internal structures, for example:
If these truly need to be bit fields, then they should be implemented explicitly using shifts and masks. However, initial inspection of the code would suggest they do not need to be bit fields, they can be made into separate fields. While this may increase the memory footprint somewhat (struct is likely to be 5 bytes in the example instead of 4) this is probably a reasonable trade, because separate fields can be simply read/written directly rather than requiring a read-modify-write etc.
Note that when using bit fields, the assembly instructions to do shifts and masks will still be generated by compiler, even though the C syntax "looks" simple - it is hiding it all. So it may be considerably less efficient than accessing separate memory locations. This of course depends on hardware architecture, caching, optimization by the compiler, etc but in general bitfields will always be less efficient, due to the extra shifting and masking.
The text was updated successfully, but these errors were encountered:
jphickey
added a commit
to jphickey/CF
that referenced
this issue
Dec 8, 2021
Bit field behavior is platform-specific, bits are not
specified to be in any particular order. Furthermore,
unions of bitfields are likely undefined behavior.
This removes the bitfields and replaces with normal
fields.
This is actually a portability bug because the bit flags in "all" are not guaranteed to be the same actual bits as the flags in the rx/tx union members. So when crossing between the two union members, undefined behavior may result. The linked PR addresses this.
jphickey
added a commit
to jphickey/CF
that referenced
this issue
Dec 9, 2021
Bit field behavior is platform-specific, bits are not
specified to be in any particular order. Furthermore,
unions of bitfields are likely undefined behavior.
This removes the bitfields and replaces with normal
fields.
Use of bitfields is discouraged by many coding standards (including GSFC) because the C standard does not specifically dictate how they are packed into the underlying integer type. CF uses them in several internal structures, for example:
CF/fsw/src/cf_cfdp.h
Lines 159 to 165 in 2ca7f97
If these truly need to be bit fields, then they should be implemented explicitly using shifts and masks. However, initial inspection of the code would suggest they do not need to be bit fields, they can be made into separate fields. While this may increase the memory footprint somewhat (struct is likely to be 5 bytes in the example instead of 4) this is probably a reasonable trade, because separate fields can be simply read/written directly rather than requiring a read-modify-write etc.
Note that when using bit fields, the assembly instructions to do shifts and masks will still be generated by compiler, even though the C syntax "looks" simple - it is hiding it all. So it may be considerably less efficient than accessing separate memory locations. This of course depends on hardware architecture, caching, optimization by the compiler, etc but in general bitfields will always be less efficient, due to the extra shifting and masking.
The text was updated successfully, but these errors were encountered: