Sometimes I see someone compile a C program like this:
gcc -o hello hello.c hello.h
gcc -o hello hello.c
Firstly, in general:
.h files are indeed typical C-style header files (as opposed to being something completely different that just happens to be named with
.h extension), then no, there's no reason to "compile" these header files independently. Header files are intended to be included into implementation files, not fed to the compiler as independent translation units.
Since a typical header file usually contains only declarations that can be safely repeated in each translation unit, it is perfectly expected that "compiling" a header file will have no harmful consequences. But at the same time it will not achieve anything useful.
hello.h as a standalone translation unit equivalent to creating a degenerate
dummy.c file consisting only of
#include "hello.h" directive, and feeding that
dummy.c file to the compiler. It will compile, but it will serve no meaningful purpose.
Secondly, specifically for GCC:
Many compilers will treat files differently depending on the file name extension. GCC has special treatment for files with
.h extension when they are supplied to the compiler as command-line arguments. Instead of treating it as a regular translation unit, GCC creates a precompiled header file for that
You can read about it here: http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
So, this is the reason you might see
.h files being fed directly to GCC.