The way bit fields are accessed in many languages is often
similar to the processing in BAR: loads perform "AND"
and "shift" operations after loading
from the source word, and stores perform "AND," "shift,"
and "OR" operations as part of storing to the
destination.
However, there is one context in which load and store operations occur
differently for bit field structures: this is when a bit
field is dereferenced implicitly in a member function (just
variable name mentioned; no member selection or pointer-to-member selection
operators are used).
In this case, the value of the implicit global variable “bitposition”
influences how load and store operations occur. The value of “bitposition”
instructs the opcodes as to the actual alignment of the bit field
structure, which does not need to be aligned on a byte
boundary.
During deserialization and serialization critical-step methods,
the variable “bitposition” is populated automatically, often
making its explicit use unnecessary. But it is possible to manually
manipulate “bitposition” to achieve “unaligned bit field”
calculation results outside of the contexts of deserialization
and serialization. Of course, this requires significant
knowledge of the data format with which the user is working.
See also: [Final expression
type result] [L-value status gain and loss]
[Overly complex expressions] [Limitations
on pointer usage] [Structure member
dereference: bit scan blocks]
|