Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 8.4 the combination of the tentative definitions
#1
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?
<t></t>
#2
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.
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 1 Guest(s)