Skip to main content
eScholarship
Open Access Publications from the University of California

UC Irvine

UC Irvine Electronic Theses and Dissertations bannerUC Irvine

Modularization of C++ Applications Based on C++ 20 Modules

Abstract

As one of the most popular programming languages, C++ is characterized by its unique header-file mechanism that provides an effective way to access the interface of a library. However, this header-based mechanism also has its weaknesses. For instance, compilers have to perform redundant work which leads to poor compiling performance, developers should write their code carefully to avoid macro collisions, declarations and implementations are separated into multiple files which increase the complexity of the project, etc. To mitigate these challenges, the C++ standards committee proposed the modules feature of C++20 in 2020, which is introduced as an improvement of the traditional header file mechanism. C++20 modules provide a better way to encapsulate codes and address most deficiencies of header files. However, since the module feature is quite new, its advantages and potential challenges are not well-understood. On the other hand, most existing C++ applications are still based on header files and the include model, and there are not enough instructions on how to modularize a header-based app into a module-based app. To bridge these gaps, the paper discusses the influence of C++20 modules and proposes H2M, a new approach for conversion of a header-based C++ app to a module-based C++ app with better compiling performance. H2M starts by determining candidate source files for modularization. Next, it bundles up similar candidate source files and identifies appropriate dependencies. Finally, H2M generates the corresponding module-based app of the given header-based app. Our empirical studies verify the effectiveness of C++ 20 modules in improving compiling performance and the feasibility of code migration. Besides, the empirical studies on several header-based C++ applications demonstrate the effectiveness of H2M.

Main Content
For improved accessibility of PDF content, download the file to your device.
Current View