MISRA Discussion Forums
Rule 8.4 the combination of the tentative definitions - 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.4 the combination of the tentative definitions (/showthread.php?tid=1164)



Rule 8.4 the combination of the tentative definitions - satoshi - 12-03-2015

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?


Re: Rule 8.4 the combination of the tentative definitions - misra-c - 11-05-2015

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.