MISRA Discussion Forums
Explicit size of array in declaration with external linkage? - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.8 Declarations and Definitions (https://forum.misra.org.uk/forumdisplay.php?fid=35)
+---- Thread: Explicit size of array in declaration with external linkage? (/showthread.php?tid=32)



Explicit size of array in declaration with external linkage? - stroelea - 23-06-2005

Whenever you change the definition of an array, the corresponding declaration for external linkage may need to be adapted (different size of array). This is error-prone since the declaration usually is included in a file different from the file with the definition. As a consequence, the code becomes inconsistent and more difficult to understand.
Moreover, the size information in the declaration with external linkage is redundant. Compilers usually ignore it.
So what are the benefits of having rule 8.12 classified as a \"required\" rule?


- Gavin McCall - 03-11-2005

MISRA-C Steering Team 2/11/2005

We would recommend the use of a macro to define the size of the array.
This macro can be used in the definition and in the declaration of the array.

Static analysis tools CAN use this information to identify array bounds violations.