struct and union are supported since version 0.4, and this support is efficient. Unlike several other well known compilers, cpik offers full support: structs can be passed to functions as parameters and can be returned by functions.
structs are passed to function by value, as specified by the standard. Anonymous structs are supported. structs are perfectly compatible with typedef. structs entities can be affected to other entities of same type.
structs are guaranteed to be compact: as PIC-18 architecture does not impose any alignment constraint, the size of a struct is the sum of the sizes of its members12.
structs cannot be larger than 128 bytes13, but I suppose it is not a terrible limitation for a 8 bit microcontroller.
Members of structs can be signed or unsigned bit fields. As stated by the standard, a bit field cannot cross an int boundary, so the size of a bit field can range from 1 to 8 bits. For example, in the following code
struct XXX { unsigned a: 4 , b: 4 ; } xxx ; struct YYY { unsigned a: 5 , b: 4 ; } yyy ;the variable xxx is exactly 1 byte long, but the variable yyy is 2 bytes long because the second field is one bit too long to be inserted in the first byte.
Bits are specified from low to high (so, in the struct XXX, a is the low nibble)
Please note that unsigned bit fields are much more efficient than their signed counterpart because they don't need to be sign extended when they are converted to int. |