AutosarC++18_10-A3.1.4

When an array with external linkage is declared, its size shall be stated explicitly

Required inputs: IR

Rationale

Although it is possible to declare an array of incomplete type and access its elements, it is safer to do so when the size of the array can be explicitly determined.

Example
//% $Id: A3-1-4.hpp 271687 2017-03-23 08:57:35Z piotr.tanski $
    #include <cstdint>
    extern std::int32_t array1[];    // Non-compliant
    extern std::int32_t array2[42]; // Compliant
See Also
  • MISRA C++ 2008 [7]: Rule 3-1-3 When an array is declared, its size shall either be stated explicitly or defined implicitly by initialization.

Possible Messages

Key

Text

Severity

Disabled

unbounded_array

Array declaration with unknown size.

None

False

Options

only_extern

only_extern : bool = True

Whether to consider only extern declared arrays.
 

report_arrays_initialized_with_string_literals

report_arrays_initialized_with_string_literals : bool = True

Whether to report character arrays without a bound that are properly initialized using a string literal. This also applies to wide character arrays.
 

report_definitions

report_definitions : bool = True

Whether definitions of array variables should also be reported.