C++ Interoperability: Header-based Imports vs. AST-based Mapping
24K reputation · 27 Jan 2026, 23:53 UTC
Interoperability Strategy for C++ Integration
Carbon aims for bidirectional interoperability with C++, allowing existing C++ code to be utilized within Carbon projects. A primary design challenge involves determining the mechanism for importing C++ types and functions while maintaining language integrity.
One approach relies on header-based imports, utilizing a C++ compiler frontend to parse headers and map types directly. This simplifies adoption by leveraging existing C++ build artifacts. Conversely, an AST-based bridge would map C++ structures to a structured representation, avoiding preprocessor complexities and enhancing type safety at the cost of increased implementation overhead.
The decision impacts how C++ templates are handled when instantiated within Carbon code and whether interoperability remains a separate translation layer or a first-class compiler feature.
- Which approach provides the most reliable type safety for complex C++ template instantiations?
- Does the AST-based mapping introduce prohibitive overhead compared to header-based parsing?