MISRA Discussion Forums

Full Version: Rule 8.4 the combination of the tentative definitions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How should treat the combination of the tentative definitions?

Code:
int i;  /* treated as declaration ? */
int i;  /* treated as definition ? */

or...
If only tentative definitions exists, we should consider that the compatible declaration is not exist?
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:
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
Quote: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.