Explicit bit fields

This very handy feature allows to use any bit slice of a 8 bit variable in an expression. For this purpose, cpik provides the non-standard syntax

 var.OFFSET:SIZE
which corresponds to a slice of SIZE bits starting at bit number OFFSET of var.

Notice that :

  1. The above syntax is not the invocation of an operator, it just a way to define a temporary sub-variable corresponding to a bit slice. As a consequence, var must be an existing variable identifier and cannot be an expression.
  2. OFFSET and SIZE must be integer constants, or integer constant expressions. ( OFFSET can range from 0 to 7 and SIZE can range from 1 to 8).
  3. Obviously, OFFSET+SIZE cannot be higher than 8 because a bit field cannot cross a byte boundary.
  4. A bit field that is 8 bit wide is not rejected, but is viewed as a plain byte by the compiler.

As an example, suppose we need to copy PORTB<0-3> (configured as input) to PORTB<7-4> (configured as output).

Note that explicit bit fields are always unsigned.

Alain Gibaud 2015-07-09