Let's say I have two source files: main.c
and a.c
:
main.c
:
#include <stdio.h>
int a;
int i;
int i;
int main(void)
{
printf("a = %d\n", a);
printf("i = %d\n", i);
return 0;
}
a.c
:
int a;
Then, according to latest C99 draft 6.9.2
External object definitions p. 2 (emphasis mine):
A declaration of an identifier for an object that has file scope without an initializer, and without a storage-class specifier or with the storage-class specifier
static
, constitutes a tentative definition. 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 behavior is exactly as if the translation unit contains a file scope declaration of that identifier, with the composite type as of the end of the translation unit, with an initializer equal to 0.
Compilation (no warnings given):
gcc -g -std=c99 -pedantic-errors -Wall -Wextra main.c a.c
I understand that for i
variable there two are tentative definitions and since main.c
does not have "true" external definition they are merged into such one. What about a
? Do I state correctly, that tentative definitions are not "shared" between multiple source files (i.e. translation units) ?