Say I declare the following variable:
int num;
num = 0;
int main(void)
{
/* ... */
exit(EXIT_SUCCESS);
}
The compiler will complain about num
being undeclared and that it will default to type int
. This does not happen when I do it all in one step:
int num = 0;
or if I move the assignment into main()
:
int main(void)
{
num = 0;
/* ... */
exit(EXIT_SUCCESS);
}
I once read an explanation for this behavior but I cannot find it anymore. Could someone update me again.
I'm compiling with
gcc -std=c11 -O2 -g -pedantic -Wall -c -fmessage-length=0 -v