1

So C++20 promises the new modules feature, which is supposedly going to remove all the headaches of the current #include system driven by the preprocessor.

The question is: what happens with old headers?

And this question can be split into 2:

1. What happens with standard library headers like <iostream>?

I am pretty sure this is a very easy question to answer, the C++ standard must have taken care of this, but I am asking because I don't know how to do it. How would you replace the line:

#include <iostream>

with an import statement?

2. What happens with other libraries that use headers, like <windows.h>, <unistd.h> and all the other third-party C/C++ libraries?

This one seems much more difficult to answer. In our good old #include system, the library maker would compile the library into an object file or a static/dynamic library and publish it together with the .h/.hpp file containing the interface (you, as the user, would only have the source of the implementation of the library if it was an open source library).

Now, this new module system simply requires the library maker to compile the library and publish it. The rationale behind this (as I understand it) is that the linker will know what the library exports (that is all stored in the object file) and be able to link accordingly.

The problem arises when you have to use an old library that has an object file and a header file. It is safe to assume that most relevant library developers will convert their code to the new module system, but older (discontinued) libraries won't have that much luck. The object file will not have a module name inside it (because it wasn't compile as a module), so the code that uses the library will not have a module name to use. What should a library user do in this case?

DarkAtom
  • 2,589
  • 1
  • 11
  • 27
  • a cppcon talk from last year, speaker also discusses how to transition from includes to imports: https://www.youtube.com/watch?v=szHV6RdQdg8&t=1220s – 463035818_is_not_an_ai May 27 '20 at 20:06
  • So `import` used on header files works the same as `#include` (but not done by the preprocessor)? Can I just `import ;` or `import ;`? – DarkAtom May 27 '20 at 20:10
  • the `=1120s` was just by accident. I don't remember, it was some time ago I watched it. – 463035818_is_not_an_ai May 27 '20 at 20:12
  • Does this answer your question? [What exactly are C++ modules?](https://stackoverflow.com/questions/22693950/what-exactly-are-c-modules) (There are more than object files involved; you should expect to still have the header-*like* interface files distributed, and the compiled module interfaces are distinct as well.) – Davis Herring May 28 '20 at 02:50

0 Answers0