The better command to invoke gcc
in your case would be
gcc -Wall -Wextra -g test.c -o myprogram
it is asking for [nearly] all warnings, some extra warnings, and debugging information (to use gdb
)
However, GCC (or any reasonable compiler) cannot do much about a missing included file (since that missing file would probably define a lot of names needed to compile the rest of your code).
Read much more about the C preprocessor, i.e. cpp ...
Imagine that foo.h
contained #define printf(...)
(that would be a bad idea, since coding
#define printf(...) do{}while(0)
would be perhaps better -but not that much, since printf(3) is returning an integer- and would have caught your error#2), then your code would be correct.
BTW, you probably should improve your habits and compile very often (e.g. every few minutes) your source code. Also, use a version control system like git and commit your source code several times a day (when it does compile).
If you use a good editor (e.g. GNU emacs) you can easily configure it to build your project (e.g. run make
) thru M-x compile with one keypress. For a small project (less than 100 thousands lines of C source code) suitably organized in several translation units and using a good builder like GNU make recompiling it incrementally should take a few seconds at most, and you can afford doing that often.
Regarding missing return
in main
(specifically for main
) (your error#3), this is (strangely) conforming to the C11 standard §5.1.2.2.3 (of n1570):
reaching the }
that terminates the
main
function returns a value of 0