This code compiles, but I have a run time error in Visual Studio:
Run-time check failure #3 - the variable 'x' is being used without being initialized...
int x = 15;
int main()
{
int x = x;
return 0;
}
I don't understand that behavior... in the error box when I click continue the program resumes and x has a corrupted content (like -8556328
instead of 15
).
Why does this code work without a problem, and the int array is well declared?
const int x = 5;
int main()
{
int x[x] = {1,2,3,4};
return 0;
}
gcc 4.8.4
, compiles and this program can be run with-Wall -Wextra -pedantic
turned on.clang 7.0.0
compiles it, and can be run as is. However ifprintf("%d\n", x);
is added afterint x=x;
(I guess any actual usage ofx
), the compiler gives the more friendly warning:warning: variable 'x' is uninitialized when used within its own initialization [-Wuninitialized]
.gcc
still compiles and runs it even with theprintf
and printed0
. However running the program through valgrind givesConditional jump or move depends on uninitialised value(s)
– Joakim 20 hours ago