Posts

Showing posts from March, 2014

Ada vs C++ Bit-fields

Uses of Bit-fields Bit-fields are typically used to implement communication protocols and to create device drivers for actuators or sensors. Frequently the actuators or sensors will use A/D and D/A converters to associate specific bit groupings with analog voltages on device connector pins.
In safety critical systems the bit patterns of the bit-fields must be correctly arranged or communication with the actuator or sensor will be incorrect. Since many safety critical systems require command of actuators, combined with resulting sensor readings to provide a closed loop control system, the ability to correctly define the bit layout for each device interface is highly safety critical.
JSF C++ Coding StandardAV Rule 154 (MISRA Rules 111 and 112, Revised) Bit-fields shall have explicitly unsigned integral or enumeration types only.



Rationale: Whether a plain (neither explicitly signed nor unsigned) char, short, int or long bit-field is signed or unsigned is implementation-defined.[10] Thus,…
Ada vs. the JSF C++ Coding Standard
In this article I compare safety critical C++ coding rules for arrays with built in Ada array capabilities.
Use of Arrays C and C++ array indexing always begins at 0 because that indicates a 0 offset from the address of the start of the array. The array name is actually a pointer the the start of the array. The index value is used to calculate the memory address offset from the beginning of the array. It is implied that array index values should always be non-negative. Neither the C nor C++ languages provide rules for compilers to check the validity of array indices. Any offset from the beginning of the array is allowed, including negative offsets, which will access memory locations with lower memory addresses than the beginning of the array.
AV Rule 96 Arrays shall not be treated polymorphically. See Meyers [7], item 3.
Rationale: Array indexing in C/C++ is implemented as pointer arithmetic. Hence, a[i] is equivalent to a+i*SIZEOF(array element). Si…