I am currently playing with C++ modules, trying to modernize our company's code C++ base to use modules for the core features. In particular there is the upcoming C++23 std
module which seems very interesting as a better alternative to precompiled headers.
So I am using Visual Studio 2022 17.5 Preview 2.0, which has a preliminary support for std
module. By the way, I faced a compiler internal error, a bug that I reported to Microsoft.
In all our C++ source files, there is now an import std;
statement, and this works quite well. Every identifier that is supposed to be in std
namespace seem to be exported as expected. I measured a slight decrease of compilation time compared to the previous use of a precompiled header.
I found out that if you import std;
, you have a lot of weird compilation errors in you also #include <>
any standard C++ header, because Microsoft compiler get confused and complains about redefinition. So I took care of removing all of them.
My problem is that there are a few macros that are defined in standard library (mostly in C compatibility library), which are obviously not exported because C++ modules by design never export macros.
Our code base use a very limited number of those standard macros, but I think it would be hard to avoid them. Here is the short list of them (unsure it is complete):
stdout
errno
va_start
,va_arg
,va_end
For the va_*
macros, I #include <stdarg.h>
and it compiles fine on VS 2022, although it breaks the rule I previously mentioned. This is probably because this header has nearly only macros. But for stdout
and errno
, I don't know what to so.
Does C++23 specify how to access the important standard macros like stdout
or errno
when importing std
module? Is there a good workaround?
std.compat
. – Rhuva_start
,va_arg
, andva_end
can be wholly replaced by variadic templates and fold espressions; so there's one off the list. – Blowzystd.compat
module is a Microsoft extension. And this does not export macros. – Amphora