Let us say I have only one file in my project called test.c; the code below does not compile if I do not define “TRUE”. I just want to understand the behavior. Please throw some light on this aspect.
#ifdef TRUE
static int a;
extern int a;
#else
extern int a;
static int a;
#endif
int main (void)
{
a =10;
printf("%d", a);
return 0;
}
When
TRUEis not defined, the first declaration (extern) saysahas external linkage (ISO/IEC 9899:1999, 6.2.2, paragraph 4, no prior declaration). The second declaration (static) statesahas internal linkage (paragraph 3). An identifier cannot have both internal and external linkage (paragraph 7).In the
TRUEdefined case, theexternin the second declaration has no impact because there is a prior declaration declaringawith internal linkage (paragraph 4).See draft of ISO/IEC 9899:1999.