Rule 8.3: int n[4] vs. int n[] ?

Moderators: misra-c, david ward

Post Reply
swestin
Posts: 8
Joined: Wed May 28, 2014 6:53 pm
Company: GrammaTech Inc.

Rule 8.3: int n[4] vs. int n[] ?

Post by swestin » Tue Feb 06, 2018 2:46 pm

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

Code: Select all

<file A>
int n[4];

<file B>
int n[];

misra-c
Posts: 571
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 8.3: int n[4] vs. int n[] ?

Post by misra-c » Fri May 04, 2018 11:17 am

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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.8 Declarations and defnitions”