In C you can do this:
static const int a;
int main(){}
And it seems to be fine. C99 §6.7.8p10 says:
If an object that has static storage duration is not initialized explicitly, then:
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
Similarly C++14 §3.6.2p2 says:
Variables with static storage duration (3.7.1) or thread storage duration (3.7.2) shall be zero-initialized (8.5) before any other initialization takes place.
The difference is in C++14 it needs an initializer §8.5p7:
If a program calls for the default initialization of an object of a const-qualified type
T
,T
shall be a class type with a user-provided default constructor.
So I'm asking why is an initializer required in C++? No initializer is required if a
is not const
, so what difference does const
make here that would make no initializer bad?