Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A3-9-1 - example with plain 'char' type
The A3-9-1 rule recommends to use integer types from <cstdint>, indicating the size and signedness, but the plain 'char' type does not have corresponding type in this library. It is possible to replace only explicit signed or unsigned 'char' types.

The example in A3-9-1 shows the declaration of the plain 'char' type as non-compliant. I understand that in this case the 'i6' variable is initialized by numerical value, so its type should be changed to int8_t. However, this is a different problem that is non-compiant with Rule M5-0-11 "The plain char type shall only be used for the storage and use of character values.". The plain 'char' type is used in AUTOSAR documentation in cases which are marked as compliant (for example Rule A5-1-1). I suppose that A3-9-1 should apply only to 'char' types declared explicitly as signed or unsigned and should not apply to plain 'char' types.
I could be offbase but I believe the reason for the "plain char" rules is that text strings made of plain char could occupy different cell sizes on a platform by platform basis. It woudln't make sense to require int8 if int8 wasn't the native char size on machine XYZ.

So, while according to A3-9-1, char is noncompliant, IMHO, it is a necessity and an example of one of many AUTOSAR rules that seemingly contradict each other. I would mark it as a flagged excpetion or disable the warning, and move along.
The rule’s rationale is imprecise in stating “the basic numerical types of char, int …”. What is intended here is to say “signed char, unsigned char, int, short …”.

Plain char is not considered to be a numerical type in Autosar/MISRA, so A3-9-1 does not apply, see M4-5-3  & M5-0-11.
The example “char i6 = 23;” is incorrectly marked as non-compliant. It should be marked as “rule does not apply”. It is indeed non-compliant with respect to M5-0-11
Posted by and on behalf of
the MISRA C++ Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)