Do I need to compile the header files in a C program?

前端 未结 5 886
生来不讨喜
生来不讨喜 2020-12-23 12:32

Sometimes I see someone compile a C program like this:

gcc -o hello hello.c hello.h

As I know, we just need to put the header files into the C p

5条回答
  •  佛祖请我去吃肉
    2020-12-23 13:04

    In some systems, attempts to speed up the assembly of fully resolved '.c' files call the pre-assembly of include files "compiling header files". However, it is an optimization technique that is not necessary for actual C development.

    Such a technique basically computed the include statements and kept a cache of the flattened includes. Normally the C toolchain will cut-and-paste in the included files recursively, and then pass the entire item off to the compiler. With a pre-compiled header cache, the tool chain will check to see if any of the inputs (defines, headers, etc) have changed. If not, then it will provide the already flattened text file snippets to the compiler.

    Such systems were intended to speed up development; however, many such systems were quite brittle. As computers sped up, and source code management techniques changed, fewer of the header pre-compilers are actually used in the common project.

    Until you actually need compilation optimization, I highly recommend you avoid pre-compiling headers.

提交回复
热议问题