cppreference states:
Every declaration is a definition, except for the following:
and then I do not see non-static(local) variables on the list of exceptions. However, I get why that static variables are considered as defined when declared since they are initialized to zero. BUT non-static variables are indeterminate, so are those non-static variables considered as being defined when being declared - as with static variables?
Example:
int x; // zero
int y = 0; // also zero
void foo() {
static int x; // also zero
}
So here all the x
and y
are initialized to zero and therefore I think I get it if those declarations are considered as definitions.
But
void foo() {
int x;
printf("%d", x); // the compiler is free to crash here
}
Is the declaration of x
also a definition, I mean this declaration does not really initialized to anything, right?
In fact, I have always thought that there was a pretty obvious difference between declarations and definitions, like int x;
, class X;
vs. int x = 2
and class X {};
.
Also, if it is true that the declarations static variables also are definitions, why are static class members included in the exception list and not static variables that are not a member of a class?