r/cpp • u/xeeeeeeeeeeeeeeeeenu • Nov 13 '22
gcc 13 will have <format>
https://gcc.gnu.org/pipermail/libstdc++/2022-November/054991.html51
u/qalmakka Nov 14 '22
Big fat question: given that {fmt} is MIT/X11 licensed, couldn't they just import the bits necessary to implement <format> from it and simply adapt it to work well with libstdc++? It feels a bit wasteful reimplementing it from scratch, AFAIK MSVC's STL did exactly that.
Is this just good old NIH or there's some copyrights/patents related issue underneath this decision?
9
u/archysailor Nov 14 '22 edited Nov 14 '22
IIRC all rights to code committed to GNU projects have to be waived to the FSF so they have maximal freedom with future licensing decisions. I don’t think anyone expects the libfmt authors to consent to that easily.
Edit: This is wrong. See u/Jannik2099’s reply.
6
9
u/eidetic0 Nov 14 '22
does anyone know what this means in terms of gcc release cycles? will 13 get a release this year?
29
u/catcat202X Nov 14 '22
GCC releases roughly once a year, and 12 came out earlier this year so no, GCC 13 is likely next Summer. https://gcc.gnu.org/develop.html#timeline
I compile GCC 13 from its Git repo, which isn't too difficult usually. Although for the life of me I can't get the stack traces runtime to compile. There are also nightly archives of the source, and someone has automated binary releases for 4 years. https://jwakely.github.io/pkg-gcc-latest/
40
2
u/blankettripod32_v2 Nov 14 '22
GCC 13 is already available in source, you can compile it yourself right now
16
u/AKostur Nov 13 '22
Sweet! Been looking forward to it!
7
u/el_muchacho Nov 14 '22
Too bad someone wrote a library that is even better and slightly faster
0
Nov 14 '22
[deleted]
15
u/qoning Nov 14 '22
Every software's story is one of iteration. The C++ standardization however does not allow this to happen to a sufficient degree.
To myself, backwards compatibility and abi stability is a plague on the language because it makes the standard library measurably worse than it could be. But I get that for someone else it could be a blessing.
7
u/Jannik2099 Nov 14 '22
abi stability is a plague on the language because it makes the standard library measurably worse
Literally the only thing an ABI break would solve is std::regex. It's by far not worth the downsides.
Meanwhile, you got stuff like ranges, modules and soon STL coroutine support, all without ABI breaks!
9
→ More replies (4)6
u/jonesmz Nov 14 '22
Let's not forget that Google essentially abandoned c++ because of the ABI for parameter passing of types like std::unique_ptr
→ More replies (4)0
Nov 14 '22
[deleted]
7
u/serviscope_minor Nov 14 '22
Like random numbers which need three lines of code and visiting the documentation, rather than a trivial random(min, max) function that would suffice 95% of the time.
With minor caveats I very strongly disagree.
When C++ random numbers came along, I disliked them because they were so inconvenient compared to rand()%N. These days I love them. I recently wrote some Pytorch code. In common code there are actually several global RNGs with their own state. If you want to be able to do something repeatably, it's a nightmare of carefully saving and restoring states across different implementations with different APIs. What a nightmare!
Turns out you can conveniently hack code with global variables, but we don't on the whole because it goes from convenient to bad very quickly. I feel random numbers are not an exception to this.
I really like how C++ now makes the mutable state explicit and non global. Decoupling the distribution from the engine also makes the streams and the state clear (normal_distribution<> has a very sensible stateful implementation).
mt19937 engine; normal_distribution<>(0, 1) unit_normal; double d = unit_normal(engine);The caveats are of course:
Distributions are implementation defined. This is annoying in practice, but I can see why they did it. I use Boost if I need cross platform repeatability.
Setting the seed from a random device. This is some std::regex level C++
→ More replies (12)6
u/Minimonium Nov 14 '22
We're lucky the choice isn't "either standard library or hundreds of dependencies", aren't we?
1
1
u/Plazmatic Nov 14 '22
well good thing fmtlib isn't "hundreds of dependencies" and <format> isn't comprehensive.
11
u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Nov 13 '22
This is amazing news! So excited to finally be able to use format under the standard library!
7
7
8
6
u/germandiago Nov 14 '22
any progress on modules?
18
u/caroIine Nov 14 '22
There is this ticket that track all the issue with modules https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
By the looks of its history it seems that modules are 2y away.
9
u/germandiago Nov 14 '22
it is a bit disappointing. Why it takes so long? They are short on funds? Is there a way for put this back to speed? I would be willing to contribute some money if needed for working on this, but my funding alone I do not think it would be enough.
I do not have the time or knowledge, unfortunately, to work on it directly.
8
-2
u/caroIine Nov 14 '22
I would also fund salary for additional developer. But at the same time the msvc module performance isn't anything that was promised compared to pch. So maybe that's why open source devs aren't motivated enough to continue work on it.
It's just not worth it.
9
u/germandiago Nov 14 '22
It is not only compile times that improve. Isolation, ODR and others like interface boundaries improve a lot with modules.
3
u/caroIine Nov 14 '22
Yeah isolation is great, especially when it comes to third party libraries or things like windows.h but I don't think it was ever a problem. Most people wanted faster compile time.
2
u/mrbeanshooter123 Nov 14 '22
Wait what? Are precompiled headers faster than modules?
2
u/gracicot Nov 14 '22
In my experience precompiled headers can even be slower than normal headers, especially when dealing with a heavily modularized (not c++ modules) codebase. They all need their own composed precompiled header which just slows down compilation since they cannot be parallelized with the code that uses it
2
u/caroIine Nov 14 '22
I've made variants of notepad++ as a real life benchmark (all release with multi-core compilation 8core)
original (no pch or import std) 2min 37s
import std 1min 28
pch with all std 1min 23s
So lets say it's a tie. But pch is much more easier to deal with in realistic projects.
Oh and if we add system headers to pch (like windows.h) we go down to 39s (at this moment modules can't deal with windows.h)
→ More replies (2)1
u/germandiago Nov 14 '22
maybe a survey in reddit to arrange some funding campaign?
Zero experiemce but who should be the people to implement something like that and where should it be headed?
3
Nov 14 '22
This and the lack of modules support in CMake are the only things keeping me from switching to C++20. But i've played with it a bit and it's hard to go back from having concepts, constraints, and `char8_t`.
11
u/jonesmz Nov 14 '22
Why can't you switch to c++20 and just not use the parts that are missing?
c++20 concepts, for my codebase, is the killer feature. C++modules and <format> aren't interesting by comparison
2
u/marcusmors Nov 14 '22
FINALLYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY!!! :D am so Happy, I don't want to program in windows to use format :')
31
u/Zeer1x import std; Nov 14 '22
Just use {fmt} then?
It even has more features, like fmt::print, which comes to std:: in C++23.
12
u/BoarsLair Game Developer Nov 14 '22
fmt is great, but there are times that it's not practical or desired to add an external dependency. For example, if you're maintaining a C++ library that currently has no other dependencies, it's unlikely to be worth doing just for that.
5
u/Zeer1x import std; Nov 14 '22
Sure, there are good reasons to have formatting in the C++ standard, like for libraries, or if you work in a company where it's hard to approve external libraries.
But if you are programming on your own, or you can easily add another library, then I would currently consider {fmt} even when std::format is available.
1
1
1
u/brechtsanders Apr 29 '23
GCC 13 has been released. For a native Windows version see https://winlibs.com/
1
u/el0j May 03 '23
$ cat testcpp20.cpp
#include <iostream>
#include <format>
int main(void) {
std::cout << std::format("{}\n", 123);
return 0;
}
$ g++-13 -std=c++20 testcpp20.cpp -o testcpp20
$ ./testcpp20
123Finally here, but feels a bit half-baked without std::print.
The wait continues.
1
Nov 14 '22 edited Nov 14 '22
I would love to contribute to GCC but I don't have a solid compiler background. Where should I start? Something like this book? Just jumping in and seeing what sticks?
6
u/AlexReinkingYale Nov 14 '22
That's a good book. Crafting Interpreters is good too. The dragon book is an excellent reference and you should at least know what all is in there. No matter what, you'll need to get your hands dirty.
3
u/evaned Nov 14 '22
The dragon book is an excellent reference and you should at least know what all is in there.
I have mixed feelings about the dragon book that I won't get into, but what I will say is to just skip the first edition. If you get it at all, get the second.
First edition was published in the 80s, before static single assignment (SSA) form had been "invented", which is to my understanding what most compiler back ends are based around nowadays. Second edition at least covers that, though without checking I don't remember being thrilled by it.
One nice thing about 2nd edition is it has one of the best in-print discussions of garbage collection that I know of.
1
Nov 14 '22
What is your review of the "engineering a compiler" book I linked. Do you think it is good? I found it on GCC's list of compiler books:
Cooper and Torczon. Engineering a compiler.
Comment by Vladimir N. Makarov: It is close to their course in Rice University. A good book to start study compiler from parsing to code generation and basic optimizations. But if you are familiar with the compilers, you probably don't find interesting thoughts and approaches.
1
u/pjmlp Nov 14 '22
An excellent reference if only one cares about is parsers and lexers.
I would rather advise something like the tiger book, if the OP cares about how modern compilers work end to end.
1
Nov 14 '22
I want something that goes through the entire stack (front end, optimization, back end, etc) and doesn't assume I am already familiar with compiler implementation. Would you still recommend this tiger book?
2
u/pjmlp Nov 14 '22
Yes, you can see the chapters there, https://www.cs.princeton.edu/~appel/modern/toc.html
3
0
u/williamzborja Nov 14 '22
Amazing, I’m waiting this feature and the same time native way to use modules. Check for format and I continue waiting for modules.
-1
89
u/stilgarpl Nov 13 '22
Finally. If they add calendar to chrono and modules, most of C++20 features will be complete.