Rule 8.4 the combination of the tentative definitions

Moderators: misra-c, david ward

Post Reply
Posts: 7
Joined: Fri Oct 18, 2013 2:31 am
Company: Renesas Solutions Corp.

Rule 8.4 the combination of the tentative definitions

Post by satoshi » Thu Mar 12, 2015 8:12 am

How should treat the combination of the tentative definitions?

Code: Select all

int i;  /* treated as declaration ? */
int i;  /* treated as definition ? */
If only tentative definitions exists, we should consider that the compatible declaration is not exist?

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

Re: Rule 8.4 the combination of the tentative definitions

Post by misra-c » Mon May 11, 2015 8:51 am

To aid other readers of this question we will start by recapping the C99 descriptions of tentative definitions.

Your example is similar to the example "i4" in Example of section 6.9.2 of the C99 standard. This shows that the:

Code: Select all

   first "int i" is a tentative definition with external linkage 
  second "int i" is also a valid tentative definition which refers to the previous definition.
Paragraph 2 of section 6.9.2 states
If a translation unit contains one or more tentative definitions for an identifier, and the translation unit contains no external definition for that identifier, then the behaviour is exactly as if the translation unit contains a file scope declaration of that identifier, with an initialiser equal to 0.
Your example does not violate rule 8.4, but will violate rule 8.6 or 8.7 depending on the rest of the code.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.8 Declarations and defnitions”