I've read the following rule in C99 standard 6.9.3
There shall be no more than one external definition for each identifier declared with internal linkage in a translation unit. Moreover, if an identifier declared with internal linkage is used in an expression (other than as a part of the operand of a sizeof operator whose result is an integer constant), there shall be exactly one external definition for the identifier in the translation unit.
My questions:
(1) What exactly is an external definition?
(2) Why the following code does not violate this rule?
static int a = 1;
int main()
{
a += 1;
return 0;
}
I believe that you are confusing external definition with the definition that uses extern
keyword.
The definition is written in both C99/C11 in the semantics part of 6.9:
These are described as ‘‘external’’ because they appear outside any function (and hence have file scope).
In your example, the code does not violate the rule, because you have exactly one external defintion of object with internal linkage, that is:
static int a = 1;