1.8. Fix compiler warning

To fix the compiler warning as shown in Compiler Flags — Warning, let’s modify main.c as shown:

main.c (With extern)
1extern void greeting(void);
2
3int main() {
4    greeting();
5    return 0;
6}

What we have done here is added a declaration of the function greeting() in line 1, before using greeting() in line 4.

To compile that file with GCC, we would use the same command as we used before.

gcc main.c greeting.c -Wall -Werror -o greeting

The above command should pass without any warnings and generate our greeting as we did in previous sections.


As we did in previous sections, to compile on windows with Microsoft Visual C Compiler cl.exe, the command would be

cl.exe main.c greeting.c /W4 /WX /nologo /Fegreeting.exe

Now the command should pass successfully with following output:

main.c
greeting.c
Generating Code...