Although the ANSI C compliance documentation states that:
[Fields inside a structure] have addresses that increase in the order in which they are declared.
It also states the following:
According to the ANSI C standard, pointer arithmetic is to be independent of the size of the object to which the pointer points.
However, in this particular case, the pointer arithmetic is defined for a structure of all CHARs (one byte long), assuming no padding.
In the case where manual editing of the code is possible (as opposed to the current situation involving a code generator), it might be possible to use the DEFINE preprocessor directive and replace the structure with an array as follows:
#define destValue tab[0]
#define srcValue tab[1]
However, in the given situation, the code is not MISRA compliant, since it violates the following compliance rules:
17.1 (required) : Pointer arithmetic shall only be applied to pointers that address an array or array element.
17.4 (required) : Array indexing shall be the only allowed form of pointer arithmetic.
Therefore, the only solution to this issue is to use the "-allow-ptr-arith-on-struct" option and treat the orange as safe.
Best Answer