The use of double include guards in C++

前端 未结 5 2057
青春惊慌失措
青春惊慌失措 2020-12-08 01:36

So I recently had a discussion where I work, in which I was questioning the use of a double include guard over a single guard. What I mean by double gua

5条回答
  •  暖寄归人
    2020-12-08 02:11

    Although there are people arguing against it, in practice '#pragma once' works perfectly and the main compilers (gcc/g++, vc++) support it.

    So whatever puristic argumentation people are spreading, it works a lot better:

    1. Fast
    2. No maintenance, no trouble with mysterious non-inclusion because you copied an old flag
    3. Single line with obvious meaning versus cryptic lines spread in file

    So simply put:

    #pragma once
    

    at the start of the file, and that's it. Optimized, maintainable, and ready to go.

提交回复
热议问题