Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A signed bit field of 1 bit length is not useful
#1
Is it possible to improve Rule 6.5 "A signed bit field of 1 bit length is not useful". Unlike the other rules, this doesn't actually advise/recommend any behaviour or give any insight as to what compilers may or may not do when presented with this.

How about - following the same outline structure of the following rule 7.1, something like:

A signed bit field of 1 bit length is treated as ...

There is a danger of ...

They are problematic when ...

It is better not to use signed bit fields of 1 bit length use ...

Jonathan
<t></t>
Reply
#2
The rule is sort of sarcastic... It assumes you know enough of programming to just laugh and nod when you read it. What you can read between the lines is that the sign bit itself takes up one bit alone, and that it doesn't make sense to create a variable which is either "minus" or "not minus".

Also, the rule can't advise of how a compiler will react when presented with such a variable, since bit-fiends are incredibly poorly specified by the standard. Everything about them is unspecified- or implementation-specific behavior... one's complement or two's complement? First bit of the struct, lsb or msb? Big or little endian? Then there are non-standard extensions that allow other types than int...
<t></t>
Reply
#3
The use of a single bit is illogical on a target adopting two’s complement representation. The intention of the programmer may have been to allow for values of -1 and +1 (as well as zero), but such data values clearly require at least 2 bits (which in turn actually provides a range of -2 to +1). The ISO C standard does not define the required behaviour for a signed bit field of length 1.

Tracker ID: 17
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)