Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.DECL.ARRAY_SIZE

Declaration of array with unknown size.

MISRA C 2012 Rule 8.11: When an array with external linkage is declared, its size should be explicitly specified

Category: Advisory

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

This rule applies to non-defining declarations only. It is possible to define an array and specify its size implicitly by means of initialization.

Rationale

Although it is possible to declare an array with incomplete type and access its elements, it is safer to do so when the size of the array may be explicitly determined. Providing size information for each declaration permits them to be checked for consistency. It may also permit a static checker to perform some array bounds analysis without needing to analyse more than one translation unit.

Example

extern int32_t array1[ 10 ];   /* Compliant */
extern int32_t array2[ ];   /* Non-compliant */

MISRA-C 2004 Rule 8.12 (required): When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialisation.

Example

int array1[ 10 ];                 /* Compliant     */
extern int array2[ ];             /* Not compliant */
int array2[ ] = { 0, 10, 15 };    /* Compliant     */

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 may be explicitly determined.

MISRA-C++ 2008 Rule 3-1-3 (required): When an array is declared, its size shall either be stated explicitly or defined implicitly by initialization.

[Undefined 5.7(5, 6)]

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

       int32_t array1[ 10 ];                // Compliant
extern int32_t array2[ ];                   // Non-compliant
       int32_t array3[ ] = { 0, 10, 15 };   // Compliant
extern int32_t array4[ 42 ];                // Compliant