Date: Wed, 04 Dec 2024 16:40:04 +0800
And vote for (1) as strongly in favor if there was a poll : )
It is literally what we did internally and I think it is a key factor why we successed using named modules in scale.
(But I have to admit, we don’t have (or we don’t allow) complex cases as Ben mentioned.)
The implementation is not so hard, at least in clang. So if we’re in favor in this, I’d like to contribute that.
Thanks,
Chuanqi
------------------------------------------------------------------
From: SG15 <sg15_at_[hidden]>
Send Time:2024 Dec. 3 (Tue.) 14:05
To:SG15<sg15_at_[hidden]g>
Cc:James<james.business.84_at_[hidden]>
Subject:[isocpp-sg15] C++ Modules and Macros
While working with C++ modules, I’ve noticed there’s currently no way to export macros from a module. Even if you wanted to opt into this, there’s no mechanism available.
Given that macros are still essential for tasks like conditional compilation, this feels like a limitation. While macros can be controversial, they do help avoid repetitive and error-prone boilerplate in certain cases.
Using headers is still an option, but it somewhat defeats the purpose of modules since each header needs to be parsed and preprocessed for every translation unit. PCHs can help, but they’re limited to a single PCH per project and require additional setup.
I’d like to see a solution to this, but I’m unsure of the best path forward. Here are a few ideas I’ve considered:
1-) Allow exporting macros from modules (perhaps with a special directive like "#define_export").
2-) Enhance PCHs to be importable from consumed libraries. (meaning consumers will have both their own PCH(if there is one) and also consumed libraries' PCH precompiled)
3-) Introduce a mechanism for exporting macros from modules that are preprocessed only once.
It is literally what we did internally and I think it is a key factor why we successed using named modules in scale.
(But I have to admit, we don’t have (or we don’t allow) complex cases as Ben mentioned.)
The implementation is not so hard, at least in clang. So if we’re in favor in this, I’d like to contribute that.
Thanks,
Chuanqi
------------------------------------------------------------------
From: SG15 <sg15_at_[hidden]>
Send Time:2024 Dec. 3 (Tue.) 14:05
To:SG15<sg15_at_[hidden]g>
Cc:James<james.business.84_at_[hidden]>
Subject:[isocpp-sg15] C++ Modules and Macros
While working with C++ modules, I’ve noticed there’s currently no way to export macros from a module. Even if you wanted to opt into this, there’s no mechanism available.
Given that macros are still essential for tasks like conditional compilation, this feels like a limitation. While macros can be controversial, they do help avoid repetitive and error-prone boilerplate in certain cases.
Using headers is still an option, but it somewhat defeats the purpose of modules since each header needs to be parsed and preprocessed for every translation unit. PCHs can help, but they’re limited to a single PCH per project and require additional setup.
I’d like to see a solution to this, but I’m unsure of the best path forward. Here are a few ideas I’ve considered:
1-) Allow exporting macros from modules (perhaps with a special directive like "#define_export").
2-) Enhance PCHs to be importable from consumed libraries. (meaning consumers will have both their own PCH(if there is one) and also consumed libraries' PCH precompiled)
3-) Introduce a mechanism for exporting macros from modules that are preprocessed only once.
Received on 2024-12-04 08:40:09