【问题标题】:Include guards for modules包括模块防护
【发布时间】:2021-05-26 02:43:00
【问题描述】:

这可能是一个荒谬的问题,我 99% 确定答案,但我想确定。

C++20modules要求module 接口文件的任何类型的包含保护。

我的说法正确吗?到目前为止,我所读到的关于模块的所有内容都让我相信不需要保护,因为模块只编译一次,然后用于导入该模块的每个翻译单元。

【问题讨论】:

    标签: c++ visual-c++ c++20


    【解决方案1】:

    不需要包含守卫。模块只导入一次。

    预处理器定义不会从模块中转义,因此包含防护无论如何都不起作用。

    Macros, preprocessor directives, and non-exported names declared in a module are not visible and therefore have no effect on the compilation of the translation unit that imports the module.

    【讨论】:

    • 非常好,感谢您的快速回复。接受计时器结束后,我将接受您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 2013-08-08
    相关资源
    最近更新 更多