News for hackers. Stuff that matters.
Re:C++20, How Hard Could It Be by misnome on Sunday September 25, 2022 @07:26AM (#32970418)
Wait, so the words "concepts" and "requires" were newly made keywords, and this breaks code, but the words "yield" and "await" were determined too important and too common to standards members that they needed to be renamed to the horrifically ugly "co_await" and "co_yield"?

Also, last time I actually tried to use C++20 none of the standard library implementations had std::format; has this changed now?

Re:C++20, How Hard Could It Be by fouronnes3 on Sunday September 25, 2022 @08:19AM (#32970647)
One day in the far away future the standard C++ hello world will use 'import std;' and 'std::print' and it will be glorious.
Re:C++20, How Hard Could It Be by jmillikin on Sunday September 25, 2022 @08:31AM (#32970707)
When I was going to university the computer science department's primary system had two compilers available, GCC 2.96[0] and TenDRA. GCC was generally more popular but it didn't have std::string and any code that threw an exception would crash, so adventurous students would use TenDRA for development.

One of the stranger behaviors of TenDRA was that it put all standard library symbols, including the C headers, into namespace std. A hello world in TenDRA looked like this:

  #include <cstdio> // no <stdio.h> available

  int main() {
    std::printf("Hello, world!\n");
    return 0;
  }
It was not glorious. If anything ... the opposite. When TenDRA deigned to compile your program it would generally work (excepting bugs in the code itself), but getting it to accept any sort of third-party code was impossible because of the std namespace thing.

I ended up writing a bunch of utilities for strings, including a unit testing library that spawned each test as a subprocess (to avoid exceptions) just so I could use GCC instead.

[0] There is no such version recorded on the GNU project website.

Re:C++20, How Hard Could It Be by Sharlin on Sunday September 25, 2022 @09:15AM (#32971006)
C symbols are supposed to be in std if you use the cstdio style headers. It’s just that for a very long time compilers put them into the global namespace too.
Re:C++20, How Hard Could It Be by Calavar on Sunday September 25, 2022 @10:54AM (#32971900)
GCC, Clang, and MSVC all still duplicate c* header definitions into the global namespace by default as far as I'm aware.

In fact, the last time I checked, the MSVC cstdio header was implemented more or less like this:

    namespace std {
        #include <stdio.h>
    }

    using namespace std;
It's kind of crazy how major compilers have been ignoring the standard for so long that people consider a standard compliant compiler to be weird and broken.
Re:C++20, How Hard Could It Be by Forricide on Sunday September 25, 2022 @11:15AM (#32972123)
> It's kind of crazy how major compilers have been ignoring the standard for so long that people consider a standard compliant compiler to be weird and broken.

I had absolutely no idea this wasn't even supposed to be the case (although I was aware of the duplication in std::). Guess it makes sense that the standard would shy away from global namespace pollution - I suppose one of the compilers perhaps did this for long enough that the others ended up duplicating it to increase code compatibility?

Re:C++20, How Hard Could It Be by gpderetta on Sunday September 25, 2022 @05:53PM (#32976736)
That the as actually not conforming. It was made conforming in c++11 because it was pointless to have the standard say something that all major implementations would ignore.
Re:C++20, How Hard Could It Be by yyyk on Sunday September 25, 2022 @08:47AM (#32970793)
>There is no such version recorded on the GNU project website.

It's sort-of recorded. It's not in the version list since there wasn't a release, just distros making a mess:

https://gcc.gnu.org/gcc-2.96.html

Re:C++20, How Hard Could It Be by jdougan on Sunday September 25, 2022 @08:40AM (#32970750)
GCC 2.96 was a development version that incorrectly got released by Redhat on Redhat 7 (and possibly other distros).

https://gcc.gnu.org/legacy-ml/gcc-announce/2000/msg00003.htm...

Re:C++20, How Hard Could It Be by jmillikin on Sunday September 25, 2022 @09:17AM (#32971029)
This was on a DEC Tru64 system, very far from any sort of Linux.

My personal suspicion is that someone (student or faculty) got their hands on a CVS snapshot and installed it system wide. That's the only explanation I can think of for it being so broken.

Re:C++20, How Hard Could It Be by alternatetwo on Sunday September 25, 2022 @03:59PM (#32975412)
Fairly sure some PS2 SDKs also shipped GCC 2.96, which is why I know this tidbit of info.
Re:C++20, How Hard Could It Be by tolciho on Sunday September 25, 2022 @10:17AM (#32971578)
2.96 exists, at least in the RedHat world.

    $ rpm -qi gcc
    Name        : gcc                          Relocations: (not relocateable)
    Version     : 2.96                              Vendor: Red Hat, Inc.
    Release     : 110                           Build Date: Fri 12 Apr 2002 10:30:47 PM UTC
    Install date: Thu 20 Jan 2011 03:34:36 AM UTC      Build Host: daffy.perf.redhat.com
    Group       : Development/Languages         Source RPM: gcc-2.96-110.src.rpm
    Size        : 8389509                          License: GPL
    Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
    URL         : http://gcc.gnu.org
    Summary     : The GNU cc and gcc C compilers.
    Description :
    The gcc package includes the cc and gcc GNU compilers for compiling C
    code.
    $ cat /etc/redhat-release
    Red Hat Linux release 7.3 (Valhalla)
Re:C++20, How Hard Could It Be by frutiger on Sunday September 25, 2022 @10:54AM (#32971897)
Re:C++20, How Hard Could It Be by germandiago on Sunday September 25, 2022 @08:47AM (#32970789)
That will be in cpp2 already: https://github.com/hsutter/cppfront
Re:C++20, How Hard Could It Be by pjmlp on Sunday September 25, 2022 @09:41AM (#32971235)
Already available in C++23.
Re:C++20, How Hard Could It Be by tialaramex on Sunday September 25, 2022 @10:17AM (#32971577)
The future tense seems better here. This will (almost certainly) be available in C++ 23.

In the context of Chromium, this slide deck, that means in about 2026.

So if you're starting a three year degree next week, and you already know Google will hire you for the Chromium team straight after because you're the perfect person for that, you won't be writing std::print() calls in that codebase yet 'cos that's too early.

Re:C++20, How Hard Could It Be by pjmlp on Sunday September 25, 2022 @12:57PM (#32973300)
Well, they could convince their management to restart doing clang contributions for ISO C++ compliance, or maybe allocate 20% of their time for that.
Re:C++20, How Hard Could It Be by scatters on Sunday September 25, 2022 @09:46AM (#32971286)
The far away future? You mean next year?
Re:C++20, How Hard Could It Be by fouronnes3 on Sunday September 25, 2022 @11:02AM (#32971988)
I don't mean available as in the committee has published their final version of the standard that allows it. I mean available in production.
Re:C++20, How Hard Could It Be by scatters on Sunday September 25, 2022 @11:36AM (#32972354)
Oh, that'll probably be sooner, then; STL is already working on it. Also if you want to use it now, fmt has an implementation.
Re:C++20, How Hard Could It Be by layer8 on Sunday September 25, 2022 @01:14PM (#32973505)
`std::this_thread::yield` already existed at the time, and “yield” was presumed to also be a common identifier in financial and agricultural contexts.

I’m nevertheless surprised that new noncontextual and previously-unreserved-identifier keywords were added at all. In earlier times, the approach would have been to use a reserved identifier like “_Yield” for the keyword, and to provide a standard opt-in header that would `#define yield _Yield`. Maybe they don’t want to add dependencies on the preprocessor anymore.

Re:C++20, How Hard Could It Be by Sharlin on Sunday September 25, 2022 @02:06PM (#32974121)
I’m not sure C++ has ever used the `_Yield` hack, except for C compatibility? C on the other hand uses it all the time.
Re:C++20, How Hard Could It Be by layer8 on Sunday September 25, 2022 @03:07PM (#32974846)
It could be that I'm remembering it from C.
Re:C++20, How Hard Could It Be by chippiewill on Sunday September 25, 2022 @04:31PM (#32975839)
It's super common in C because C doesn't have namespaces and templates which means stuff C++ implements as namespaced library classes C has to implement as language keywords.

A good example is atomics. C++11 introduced `std::atomic`, C11 introduced the keyword `_Atomic`

Re:C++20, How Hard Could It Be by nickysielicki on Monday September 26, 2022 @12:56AM (#32979576)
Such a weak argument, you can fix this in your entire code base with a single call to sed. There is no reason to introduce a language feature with some weird prefix instead of changing existing code and having them prefix their variable names.
Re:C++20, How Hard Could It Be by AlexeyBrin on Sunday September 25, 2022 @08:05AM (#32970576)
> last time I actually tried to use C++20 none of the standard library implementations had std::format; has this changed now?

MSVC is the only major implementation that has std::format for now.

Re:C++20, How Hard Could It Be by Forricide on Sunday September 25, 2022 @11:08AM (#32972050)
It's so funny to me that MSVC has become the cutting edge of C++ standards implementation. I remember starting out when it was a joke compared to Clang - although I was a novice, so who knows how complete my knowledge was at the time.

In any case, it's a really impressive effort from STL and the rest of their library team. STL has some incredible CPPCon talks, too.

Re:C++20, How Hard Could It Be by tialaramex on Sunday September 25, 2022 @12:52PM (#32973248)
One way you could interpret this (definitely not the only way) would be that Microsoft - or some group within Microsoft - sees C++ as a possible legacy system, with an opportunity to make a lot of money by judging correctly what customers want and how much income you need to justify that support as existing offerings rust out (so to speak).

Do you have any particular CPPCon talks to recommend ?

My favourite is "Abseil's Open Source Hashtables: 2 Years In" by Matt Kulukundis, Matt's a fine speaker but what makes it so fun is that Hyrum Wright is in the audience yelling interjections as a result of Hyrum's law (this is scripted). For example Matt explains a significant size optimisation for people who only have a few things in their map, it's just smaller with no other consequences - right? Hyrum points out that now rehash happens earlier, so if you depend on it not to invalidate references during the first 15 insertions you are screwed. Guess whether any real Google code did that...

Re:C++20, How Hard Could It Be by Forricide on Sunday September 25, 2022 @01:52PM (#32973951)
I really love this talk in particular: https://www.youtube.com/watch?v=4P_kbF0EbZM (On charconv)

But any of the ones I've seen from Stephan have been fantastic, I think, although I'm not actually sure if I've seen more. He seems to have a lot of talks on very specific subjects, which can be really fun.

> Hyrum Wright is in the audience yelling interjections as a result of Hyrum's law

This sounds absolutely hilarious, I'll have to take a look.

Re:C++20, How Hard Could It Be by StephanTLavavej on Sunday September 25, 2022 @06:13PM (#32976924)
I'm glad you liked my charconv talk! Here's a complete list of my recorded conference talks:

BoostCon/C++Now 2012: Regex In C++11 And Boost: https://youtu.be/mUZL-PRWMeg

GoingNative 2012: STL11: Magic && Secrets: https://docs.microsoft.com/en-us/events/goingnative-2012/stl...

GoingNative 2013: Don't Help The Compiler: https://docs.microsoft.com/en-us/events/goingnative-2013/don...

GoingNative 2013: rand() Considered Harmful: https://docs.microsoft.com/en-us/events/goingnative-2013/ran...

CppCon 2014: STL Features And Implementation Techniques: https://youtu.be/dTeKf5Oek2c

CppCon 2015: functional: What's New, And Proper Usage: https://youtu.be/zt7ThwVfap0

CppCon 2016: tuple: What's New, And How It Works: https://youtu.be/JhgWFYfdIho

CppCon 2018: Class Template Argument Deduction for Everyone: https://youtu.be/-H-ut6j1BYU

CppCon 2019: Floating-Point charconv: Making Your Code 10x Faster With C++17's Final Boss: https://youtu.be/4P_kbF0EbZM

CppCon 2020: C++20 STL Features: 1 Year of Development on GitHub: https://youtu.be/8kjRx8vo6y4

Pure Virtual C++ 2022: MSVC C++20/23 Update: https://youtu.be/DAl37n2XOwk

Re:C++20, How Hard Could It Be by Forricide on Sunday September 25, 2022 @08:39PM (#32978038)
That's a way better list than what I had! Thanks! Think I'll watch the rand() talk tomorrow, I love (to hate on) rand.
Re:C++20, How Hard Could It Be by shadowofneptune on Sunday September 25, 2022 @01:55PM (#32973988)
I love the idea of placing a gadfly in the crowd to provide a dialogue.
Re:C++20, How Hard Could It Be by a1369209993 on Sunday September 25, 2022 @05:06PM (#32976231)
> "Abseil's Open Source Hashtables: 2 Years In"

URL seems to be https://www.youtube.com/watch?v=JZE3_0qvrMg ?

Re:C++20, How Hard Could It Be by StephanTLavavej on Sunday September 25, 2022 @08:04AM (#32970570)
std::format is available, with all C++20 Defect Reports implemented, in VS 2019 16.11.14 (and all later 16.11.x) and VS 2022 17.2 (and all later 17.x).
Re:C++20, How Hard Could It Be by nickysielicki on Monday September 26, 2022 @12:55AM (#32979570)
The east coast fintech folks are the reason we couldn’t have yield as a keyword. Too much of their code uses the variable name yield in the trading sense of the word, and so we’re stuck with this instead. This is what someone on the standards committee told me on the cpp slack a few years ago, at least.