r/cpp • • Jan 28 '19

C++ Modules Might Be Dead-on-Arrival

https://vector-of-bool.github.io/2019/01/27/modules-doa.html
280 Upvotes

240 comments sorted by

View all comments

Show parent comments

3

u/Ameisen vemips, avr, rendering, systems Jan 28 '19

Modules are a 'solution' for the fact that #include is really very brute force, and tends to bring in a lot of implementation details (including includes and such) - think when you #include <Windows.h> - it brings with it all those macros, etc.

Modules only expose what you export.

1

u/oldprogrammer Jan 29 '19

Isn't that just an issue with the structure of the header file though? If I look at the windows.h file in the MinGW distribution it is a master header file that has a collection of conditionals that include other header files as appropriate. That type of conditional inclusion could also be required in a source file importing modules.

If you drill into one of the included files as an example, winnt.h what you see is a collection of forward reference function declarations, typedefs, structures and constants defined. The macros are in-line replacements for functions so either you use the macros or define additional function calls.

Even in a module approach you need the forward declarations and structure declarations. You need the typedefs to go with the function declarations. You could ignore the #define constants but then you'd be using magic numbers or magic strings in your code.

If there are details in these headers that should be hidden and only available to the windows library that it goes with then those source files could include both an internal header and the external header.

If the information is needed by consumers of the windows library then it has to be defined in the header. So you have the same level of control over what is exposed do you not? What is magical about modules that makes them so much more needed than what is currently available?

I'm trying to understand exactly what problems modules are looking to fix that a properly defined header file and associated .so /.dll file don't already provide?

1

u/Ameisen vemips, avr, rendering, systems Jan 30 '19

I don't need 99% of the symbols Windows.h brings in, some might conflict with other code, and you cannot namespace it or otherwise hide it.

Headers make it difficult to hide implementation details, and make it easy to pollute the namespace. Modules resolve that.

And, with modules (or precompiled headers), I am including Windows.h once, and exporting the things that I want. Much lighter to bring that module into every TU than to include that header.

1

u/oldprogrammer Jan 31 '19

You might not need them but if the module developer is exporting them because others might need them you get them anyway, right?

→ More replies (8)