Formal understanding of the full type concept
I am trying to understand this concept formally. Section 13/1 says:
two declarations in the same scope that declare the same name but with different types are called overloaded declarations. Only function and function declaration template can be overloaded ; variable and declaration type cannot be overloaded.
This formally means, for example, that programs contain the following:
extern int a[5];
int a[6];
poorly formed due to different types int[5]
and int[6]
.
Now consider the declaration
extern int a[];
int a[6];
The standard says 3.9 / 6:
The declared object type of an array may be an array of unknown size and therefore must be incomplete at one point in the translation unit and finish later; the types of the arrays at these two points ("array unknown bound T" and "array N T") are different types .
But, as @MattMcNabb said in a comment earlier, this declaration declared variables of the same type. And this is natural and logical, but what "Standard" means is not clear.
As you noticed, the following is not allowed:
extern int a[5];
int a[6];
anyway there is a catch for
extern int a[];
int a[6];
§ 3.5 / 10
After all type settings (during which typedefs (7.1.3) are replaced by their definitions), the types specified by all declarations related to a given variable or function must be identical , except that declarations for an array object can indicate array types that differ in the presence or absence of the main array (8.3.4) . Violation of this rule for type identity does not require diagnosis.
This is actually an exception to the rule. It won't work if the type is different
extern int arr[];
float arr[6];
source to share