Is there any situation where you wouldn't want include guards?

前端 未结 6 782
北海茫月
北海茫月 2021-01-11 22:08

I know why include guards exist, and that #pragma once is not standard and thus not supported by all compilers etc.

My question is of a different kind:<

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 22:31

    I've seen headers that generate code depending on macros defined before their inclusion. In this case it's sometimes wanted to define those macros to one (set of) value(s), include the header, redefine the macros, and include again.
    Everybody who sees such agrees that it's ugly and best avoided, but sometimes (like if the code in said headers is generated by some other means) it's the lesser evil to do that.

    Other than that, I can't think of a reason.

提交回复
热议问题