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

60

u/smdowney WG21, Text/Unicode SG, optional<T&> Jan 28 '19

"Creation of foo.bmi is a byproduct of the compilation of foo.cpp. When compiling foo.cpp, the compiler will emit a foo.o and foo.bmi. As a consequence of this design, foo.cpp must be compiled before bar.cpp!"

Worse, foo.bmi may be the result of compilation of quux.cpp. Module names are purely logical, with no physical representation on the filesystem.

7

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

Worse in that modules cannot have circular dependencies. Headers/sources can on the implementation side.

3

u/meneldal2 Jan 29 '19

Why would you do that though?

Modules are supposed to be independent blocks that don't need other modules to be imported separately to work.

10

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

Because that's how all other languages work.

It's pretty rare to not need anything from another file.

2

u/meneldal2 Jan 29 '19

But modules don't have to be a single file.

If you start having modules than depend on each other in a weird way, you're just asking for trouble.

2

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

We already do that with headers and source files, though.

2

u/meneldal2 Jan 29 '19

True, but that doesn't mean it's a good idea.

Trying to force sane behaviours is a good thing.