Extern declaration of "array of unknown boundary T" in C ++

I compiled the following program with g ++ (7.1) and clang ++ (xcode 9.0) with -std=c++11 -Wall and get the result:

g ++

 0x10052c050 0x10052c040 0x10052c040 

clank ++

 0x108b74024 0x108b74018 0x108b74018 

This means that extern int a[]; and static int a[3]; declare the same entity and have the same relationship (internal binding).

 //a.cpp #include <stdio.h> int a[3]; void f() { printf("%p\n", (void*)a); }; //b.cpp extern void f(); static int a[3]; void g() { printf("%p\n", (void*)a); extern int a[]; printf("%p\n", (void*)a); } int main(int argc, char* argv[]) { f(); g(); return 0; } 

but in C ++ 11 [3.9 / 6]:

... The declared type of an array object can be an array of unknown size and, therefore, be incomplete at one point of the translation unit and end later; array types at these two points ("array of unknown boundary T" and "NT array") are different types ....

int a[3]; and int a[]; - different types

In C ++ 11 [3.5 / 6]:

If there is a visible declaration of an object with a binding with the same name and type , ignoring objects declared outside the innermost spanning scope of the namespace, the declaration of the block scope declares the same entity and gets a connection to the previous declaration. If there is more than one such matching object, the program is poorly formed. Otherwise, if no matching object is found, the block area object gets an external reference.

"with the same name and type is" incompatible ", therefore extern int a[]; will not receive the link of the previous declaration ( static int a[3]; ), and so:" Otherwise, if the corresponding object is not found, the subject of the block area gets an external connection. "compatible.

My question is:

  • Why does the compiler result not match the standard C ++ 11 wording?
  • Or, if my understanding is wrong, what right?

Note: this question is different from error: the extern declaration from "I" follows the declaration without binding

+7
c ++ language-lawyer c ++ 11 linkage
source share
1 answer

"extern int a []" DOES NOT COMPLETELY define "a".

Updated after comment by @Bob__ on my original post.

I get the same results on all three compilers I tried (before changing the pointer addresses) - thanks, @Bob__. Since they all compile if we say that it is a standard language that needs updating?

0
source share

All Articles