S
somenath
Hi All,
I would like to get my understanding verified for the following.
#include<stdio.h>
int g;
int g =23;
int main(void)
{
printf("\n g= %d\n",g);
return 0;
}
The question is why compilation of the code is error free.
According to me
int g;is the tentative definition of g and it has linkage as if the
"extern" keyword had been present. So it has external linkage.
In case of int g =23;
It is non tentative definition of g and the has linkage as if the
"extern" keyword had been present. So it has external linkage.
According to the C standard If, within a translation unit, the same
identifier appears with both internal and external linkage the
behavior is not defined.
As g in both the case has external linkage that’s the reason compiler
is not throwing error.
Please correct me if I am wrong.
Regards,
Somenath
I would like to get my understanding verified for the following.
#include<stdio.h>
int g;
int g =23;
int main(void)
{
printf("\n g= %d\n",g);
return 0;
}
The question is why compilation of the code is error free.
According to me
int g;is the tentative definition of g and it has linkage as if the
"extern" keyword had been present. So it has external linkage.
In case of int g =23;
It is non tentative definition of g and the has linkage as if the
"extern" keyword had been present. So it has external linkage.
According to the C standard If, within a translation unit, the same
identifier appears with both internal and external linkage the
behavior is not defined.
As g in both the case has external linkage that’s the reason compiler
is not throwing error.
Please correct me if I am wrong.
Regards,
Somenath