I have compiled and ran the following program in a C++17 compiler (Coliru). In the program, I declared an extern
variable, but did not define it. However, the compiler doesn't give a linker error.
#include <iostream>
extern int i; // Only declaration
int func()
{
if constexpr (true)
return 0;
else if (i)
return i;
else
return -1;
}
int main()
{
int ret = func();
std::cout<<"Ret : "<<ret<<std::endl;
}
Why doesn't the compiler give a linker error?