by xdavidliu · 2y ago · 0 comments
Writing this on a debian machine, and trying "g++ --std=c++23 -fmodules-ts" does not work, and from https://en.cppreference.com/w/cpp/23 looks like the "paper" for this is P2465R3, for which clang++ 17 has "partial support". I apt installed clang++17, and it still didn't work, complaining "module 'std' not found"
I understand that "import std;" is a very new feature and not "finalized" or whatever, but this book is supposed to be for beginners to C++; I wonder how the average beginner would react to that?
(I found the same thing a year or two ago when reading "Tour of C++")
My g++ emits exactly the errors and instructions you described.
I haven't read the current Stroustrup version under discussion, but I did read the earlier version when C++ was all day, every day for me.
I prefer Koenig and Moo's Accelerated C++ twenty years on though I admit there may be better books since which I've not read.
IIRC, their hello world was:
// a small C++ program
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
}
Which copy pastas into my current arch linux, builds in: g++ a.cpp
and runs in: ./a.out
Hello World!
as it has since I first read it twenty years ago, and likely did before that.The rest of the book was a tour de force of making modern C++ emulate the near-pseudocode, sans pointer arithmetic of C, simple-and-clean, buttoned-up style seen in early python, where none of those things existed until pandas brought wrapped C++ libs along with it like numpy and scipy.
Professionally, I've not seen clean C++ code in the wild, though I don't work at FAANG and code reviews are unusual in rapid prototypes so I'm not sure how widely Koenig and Moo are mentored outside the greenfield world I've lived in with the possible exception of radiotherapy where you're trying to avoid being the next Therac 25.
"_Standard Library Header Units_
The Standard Library is not provided as importable header units.
If you want to import such units, you must explicitly build them
first. If you do not do this with care, you may have multiple
declarations, which the module machinery must merge--compiler
resource usage can be affected by how you partition header files
into header units."
So for now any "import" can work only if one writes appropriate module files first.Nevertheless, I do not expect that the updating of the standard C++ library of gcc will take a long time, so later this new book will become directly usable as it is.
For someone who already knows older C++ and just wants to update their knowledge, writing the corresponding module files can be a good learning experience in itself.
But mostly, it's not realistic to directly wire up calls to g++ anymore outside of research examples. Note that other compiled languages use systems like gobuild, cargo, Maven, etc. instead of fiddling with gccgo, rustc, javac, etc. directly.
> CGG (sic) uses .cxx for module files Use -fmodules to use modules.
no it does not. Trying this on Fedora 39 for example, my original comment above already had -fmodules-ts, and when I use -fmodules, g++ errors with
g++: error: unrecognized command-line option ‘-fmodule’; did you mean ‘-Mmodules’?