MISRA Discussion Forums
Rule 8.3: int n[4] vs. int n[] ? - 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.8 Declarations and defnitions (https://forum.misra.org.uk/forumdisplay.php?fid=163)
+---- Thread: Rule 8.3: int n[4] vs. int n[] ? (/showthread.php?tid=1398)



Rule 8.3: int n[4] vs. int n[] ? - swestin - 06-02-2018

Within the context of this rule, is the following definition/declaration pair allowed?

Code:
int n[4];


int n[];



Re: Rule 8.3: int n[4] vs. int n[] ? - misra-c - 04-05-2018

The example is compliant with rule 8.3 as the type name is the same, there are no type qualifiers and the size is not considered by this rule.

However, the code does violate other MISRA C:2012 rules.

In both cases the array declaration are "Tentative definitions" ( C99 6.9.2(2) ). Assuming that there are no other declarations/definitions of "n".
int n[4]; is a "tentative definition" which resolves to a definition of array with size 4 with external linkage at the end of the translation unit for File A.

int n[]; is a "tentative definition" which resolves to a definition of array with size 1 with external linkage at the end of the translation unit for File B.

The code violates rules 8.4, 8.6 and 8.11.