Why use precompiled headers (C/C++)?

后端 未结 5 451
傲寒
傲寒 2020-12-01 01:00

Why use precompiled headers?


Reading the responses, I suspect what I\'ve been doing with them is kind of stupid:

#pragma once

// Defines used         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 01:08

    In C/C++, the #include mechanism is a textual copy of the file specified into the current file. Headers include other headers (which include yet other headers), so when you do a #include, it could be adding tens of thousands of lines of C++ into each cpp file (or cxx, c, whatever), all of which need to be compiled each time. This can be a sever bottleneck for large projects.

    Precompiled headers speed this up by compiling each header once, then including that compiled state into the cpp they are included in.

提交回复
热议问题