Translation units
A program consists of one or more translation units. A translation unit consists of an implementation file and all the headers that it includes directly or indirectly. Implementation files typically have a file extension of cpp or cxx. Header files typically have an extension of h or hpp. Each translation unit is compiled independently by the compiler. After the compilation is complete, the linker merges the compiled translation units into a single program.
module
A module is a set of source code files that are compiled independently of the translation units that import them. Modules eliminate or greatly reduce many of the problems associated with the use of header files, and also potentially reduce compilation times. 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.
After a module is compiled once, the results are stored in a binary file that describes all the exported types, functions and templates. That file can be processed much faster than a header file, and can be reused by the compiler every place where the module is imported in a project.
参考&推荐阅读
microsoft c++ ducument:https://docs.microsoft.com/en-us/cpp/cpp/?view=vs-2019
wiki:https://wikipedia.org/wiki/Translation_unit_(programming)
本文介绍了程序中模块化的重要性,区分了Translationunits(翻译单元)与模块的概念,强调了模块如何独立编译、减少依赖并加速项目效率。通过Microsoft C++和维基百科的资源,探讨了模块化如何提高编译速度和代码组织的整洁性。
899

被折叠的 条评论
为什么被折叠?



