The global array is defined twice, but still compiling?

In ah, I created an array without a keyword externby mistake, which should lead to a preliminary definition

a.h:

    MyStruct myArrayOfStructs [];

This array is then defined in a.cpp

a.cpp:

MyStruct myArrayOfStructs[CONSTANT];

This is amazingly compiled.

Why didn't the compiler complain about overriding?

+4
source share
3 answers

This is illegal C ++, as you expected.

3.1 / 2:

- , , extern , , , , enum, , , , typedef, , , static-assert, , , using, , .

, .

3,1/5:

, .

, " " C .

clang++ " error:

+2

. (.h) , -, .

.

+6

, , extern. , , - , .

int i;
int i;

- legal code.

int i = 5;
int i = 6;

is not a legal code because the former is not a preliminary definition.

+2
source

Source: https://habr.com/ru/post/1599583/


All Articles