MISRA C:2012 Rule 18.10
Description
Rule Definition
Pointers to variably-modified array types shall not be used.1
Rationale
If you use pointers to variably modified array types to declare an object or a
parameter, the compatibility of the object and the array type cannot be determined in
compile time. For example, in this code, the variably modified array type parameter
array
is used for declaring the array myarray
. The
two variably modified array type objects are compatible only if the value of the parameter
length
equals 20
. The compatibility of these arrays
cannot be determined at compile time.
void foo(int length, int (*array)[length]){ int (*myarray)[20]; myarray = array; }
length
is not
20
, the behavior of this code is undefined. To avoid undefined
behavior, do not use pointers to variably modified array types.Polyspace Implementation
Polyspace® reports a violation is a pointer to a variably modified array type is used for declaring an object or a function parameter.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Pointers and arrays |
Category: Mandatory |
AGC Category: Mandatory |
Version History
Introduced in R2025a
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.