Rule 13.6 - VLA, 'volatile' and Rule Exception - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 8.13 Side effects (https://forum.misra.org.uk/forumdisplay.php?fid=168) +---- Thread: Rule 13.6 - VLA, 'volatile' and Rule Exception (/showthread.php?tid=1319) |
Rule 13.6 - VLA, 'volatile' and Rule Exception - RichardC - 28-02-2017 A qualifier in the declaration of an array applies to the element type, C11 6.7.3/9: Quote:If the specification of an array type includes any type qualifiers, the element type is so- Code: uint32_t f1 (int32_t x) { The Exception to this rule includes: Quote:... is an lvalue with a volatile qualified type that is not a variable-length array... Given that the qualifier applies to the element type and not the array type, "not a variable-length array" is always true for an lvalue with volatile type. Is it the intention for 'sizeof(a1)' to be non compliant and for 'sizeof(a2)' to be compliant? The Exception could be seen to add to the set of non-compliant cases even though nothing is written explicitly in the Amplification or Rationale. Regards, Richard Re: Rule 13.6 - VLA, 'volatile' and Rule Exception - misra-c - 14-06-2017 The MISRA-C working group agrees that the wording of the exception could be improved. The aim of the exception was to permit expressions with a volatile type, but not if the expression also contains a VLA declaration. The exception should be interpreted as follows. sizeof(V) is permitted where V is an expression which: 1. Yields an lvalue with a volatile qualified type; and 2. Does not include a declaration of a variable-length array. In conclusion, both a1 and a2 are compliant with this rule as the type being accessed is an "array type" not a volatile type. |