From section (6.2.2/7) C99 Standard
7.If, within a translation unit, the same identifier appears with
both internal and external linkage, the behavior is undefined.
While the following generates a compile time error due to conflict of definitions
// 'x' has external linkage
extern int x;
// Here, 'x' has internal linkage
static int x;
But the following compiles fine,
// 'x' has external linkage
extern int x;
void foo() {
// Here, 'x' has internal linkage
static int x;
}
Do both the cases invoke an undefined behavior?
Your question stems from an incorrect assumption that a locally declared static variable has internal linkage. In reality a static variable declared in a block scope has no linkage. See 6.2.2/6
Only file-scope declaration can have external or internal linkage (plus local
externdeclarations).Therefore 6.2.2/7 and your question simply do not apply.