Why isn't C/C++'s “#pragma once” an ISO standard?

前端 未结 9 1696
说谎
说谎 2020-11-28 11:29

I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can g

9条回答
  •  猫巷女王i
    2020-11-28 12:07

    A pragmatic solution:

    1) choose some consistent guard-naming policy (e.g. path relative to project root + file name, or whatever else you choose). Include possible exceptions for third-party code.

    2) write a program (a simple python script would do) to walk recursively the source tree and verify that the guards all conformal to the policy. And whenever the guards are wrong, output a diff (or sed script, or whatever else) that the user can easily apply to fix. Or just ask for a confirmation and make changes from the same program.

    3) make everyone on the project use it (say, before submitting to source control).

提交回复
热议问题