Hello. I decided to find out what really tentative variable is. I thought that I understand that, but when I run this code I realized that I don't. Tentative definition without any initialization is initialized to zero, isn't it? I expect that this code is not possible to compile and output from gcc will be something like "Multiple definition error" because:
If the end of the translation unit is reached and no definition has appeared with an initializer for the identifier, then the tentative definition becomes a
full definition, and the object defined has uninitialized (zero-filled) space reserved for it.
Full definition means that this variable is definied and initialized to zero in this case. That is the reason why I expect Multiple definition error. But It works good and the output was:
>0<0040da20
>0<0040da20
Was that tentative variable mysteriously changed to extern storage class or what? Does it mean that I don't need an extern keyword to share variable among .c files?
I'm so sorry for ma bad English. I hope you understand my problem. Thanks!
Code:
test.h
int a; //tentative variable without extern
void test(void);
test.c
#include <stdio.h>
#include "test.h"
void test(void){
printf(">%d<%p", a,&a);
}
main.c
#include <stdio.h>
#include "test.h"
int main(void) {
printf(">%d<%p\n", a,&a);
test();
return 0;
}