extern int a;
int a = 1;
int main(void)
{
return 0;
}
Is this UB? standard says in 6.2.2/7
If, within a translation unit, the same identifier appears with both internal and external
linkage, the behavior is undefined.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is perfectly defined behavior. And this is what the compiler would get after pre-processing after an header is included.
Your confusion seems to come that:
has not internal linkage. At file-scope
ahas external linkage. It would have internal linkage if thestaticspecifier was added.