Because function definitions are included in the executable at link time, but decalization or syntax checking is done at compile time
Consider also that when you call a function, and the compiler cannot find the function declaration, then it will generate a warning as an implicit declaration of func() .
To remove this warning, we provide a direct declaration of the func function, int func(); and compiled without warning.
Why do you think this is happening? This is because the compiler did not find the func() character. All this is up to the compiler to make error-free code in accordance with the grammar of the language.
But the construction of the final executable file is performed during the link, and then the linker started looking for the deftion func() function, if found, then fine, and if not, then Linker error
could not have resolved external symbol _func()
Note: any external characters are allowed during connection
In gcc only for compilation use this: (this may vary depending on the compiler)
gcc -Werror -c test.c It will generate a test.o file
then try linking it and making an executable
gcc -Werror -o test test.o test is executable
source share