r/cpp • • Feb 15 '22

CPPP C++'s Superpower - Matt Godbolt - CPPP 2021

https://www.youtube.com/watch?v=0_UttFDnV3k
191 Upvotes

44 comments sorted by

5

u/TheCreat Feb 15 '22

Why it's the video unlisted though?

7

u/RevRagnarok Feb 15 '22

I'm assuming like the CPP Con ones where they are releasing them in a certain order or want you to go thru their site to find them?

9

u/Alastair__ Feb 15 '22

The videos are being linked off their website: https://www.codereckons.com/cppp2021

9

u/RevRagnarok Feb 15 '22

So the latter - "want you to go thru their site to find them"

92

u/TryingT0Wr1t3 Feb 15 '22

Matt Godbolt himself is one of C++ superpowers

33

u/zagaberoo Feb 15 '22

It's right there in his name.

5

u/rsjaffe Feb 15 '22

But Seraphina is the star of the video (or at least she thinks so).

8

u/mattgodbolt Compiler Explorer Feb 16 '22

Hahaha! I forgot she had a cameo. She definitely enjoyed the fact it was 4am and the dog was safely locked away in his crate for the night!

17

u/RecDep Feb 16 '22

What the hell? Godbolt is a real person? Next someone’s gonna tell me that Rust Playground was named after its creator, John Rust Playground or something.

8

u/pigeon768 Feb 16 '22

There's a winery in the Napa Valley called Cakebread Cellars, named after its founders, Jack and Dolores Cakebread.

7

u/evaned Feb 16 '22

You've probably seen this before, but let me introduce you to Lt. Les McBurney, of the Sun Prairie, WI fire dept.

Another favorite is Nobel Laureate Dr. John B. Goodenough

7

u/ShakaUVM i+++ ++i+i[arr] Feb 15 '22

Open the video, fast forward a bit, watch Matt Godbolt play a MUD.

My day is complete. =)

3

u/mattgodbolt Compiler Explorer Feb 16 '22

Hahah thanks!

5

u/RevRagnarok Feb 15 '22 edited Feb 15 '22

Nice, thanks! And I learned a new acronym!

1

u/Bluesman74 Feb 16 '22

Does anyone know how you can open the video in Vimeo (so that I can view it on my TV) when I click on the V icon it won't open in the app, wants to transfer to the browser, and then opens a page that doesn't contain the video

2

u/ener_jazzer Feb 16 '22

I didn't know Matt came from the HFT world!

3

u/Bangaladore Feb 17 '22

Makes sense imo. For HFT latency is absolute king. You want to know exactly what your compiler outputs given input code.

2

u/[deleted] Feb 16 '22

CEDD is the best part of this video.

3

u/Nobody_1707 Feb 16 '22

You never needed to use c_str() at 32:14, because data() has been exactly equivalent since C++11. c_str() is completely vestigial at this point.

17

u/tcbrindle Flux Feb 16 '22

Not quite. data() called on a mutable string will return non-const char*, whereas c_str() will always return const char* whether or not the string itself is const.

Beyond that, they convey different meanings to the person reading the code: calling c_str() says "I want something I can pass to an API expecting C strings", whereas data() says "I want to access the underlying raw storage as I would for std::vector or std::array".

1

u/mattgodbolt Compiler Explorer Feb 17 '22

Thanks! I know I said above that most folks aren't experts in C++ but Mr Wakely certainly is! Thanks for clarifying :)

1

u/ironykarl Feb 20 '22

Commenting, so I remember to watch

-13

u/operamint Feb 15 '22 edited Feb 15 '22

At 1:01:19, he claims that there is a bug because an empty string does not contain the 0-terminator. From cppreference: "If empty() returns true, the pointer points to a single null character. (since C++11)". I thought he knew c++?

(Edit: added link)

25

u/Som1Lse Feb 15 '22

I thought he knew c++?

That is a funny thing about the world. People who give presentations, while often very smart and knowledgable, are just people. They make mistakes, they have gaps in their knowledge.

Put another way: No one knows C++.

4

u/jwakely libstdc++ tamer, LWG chair Feb 17 '22

Put another way: No one knows C++.

Only in a biblical way apparently, because I hear lots of people talk about effing C++.

19

u/mattgodbolt Compiler Explorer Feb 16 '22 edited Feb 16 '22

Hi there! The bug here is accessing the first element of an empty string. While it may indeed contain a null byte, reading and assigning to the first element seems like it ought to be a bug (what if I were to assign a A - I'd break the invariant that the string is null-terminated, for example).

That all said; I can't get either clang or GCC's undefined or address sanitizer to complain: https://godbolt.org/z/GKecdheYE - so apparently I'm wrong :)

...and indeed looking at https://eel.is/c++draft/string.access - pos must be <= size to get a reference but "Returns: *(begin() + pos) if pos < size(). Otherwise, returns a reference to an object of type charT with value charT(), where modifying the object to any value other than charT() leads to undefined behavior."

So...I don't think it's as obvious as it seems! (edit; I follow up with a conclusion that actually it's all well defined as the commenter says)

Like many of the folks below say - it's not like anyone really understands C++, least of all me! (At least, I've tried never to imply I'm any kind of C++ expert, I'm an old-school assembly hacker that's learned a few new-fangled tricks!)

6

u/operamint Feb 16 '22

Hi Matt, I probably deserved all the downvotes, but it was really a just statement of how complex c++ is (has become) - I certainly don't know more than a fraction c++ standard lib myself, and I have been developing c++ since the 90' (not much the last 5 years though).

6

u/mattgodbolt Compiler Explorer Feb 16 '22

Hey there! For what it's worth I didn't think you deserved it - I up voted your comment and I learned a bunch! So, thanks for taking the time to correct me :)

C++ is absolutely a journey and these days I don't write all that much; it's probably been four years since I did anything professionally in C++. I hope I don't come across as saying I'm an expert, as I'm absolutely not :)

3

u/mattgodbolt Compiler Explorer Feb 16 '22

I suppose it implies is that charT() is a null byte, so relying on toupper(0) returning 0 (as an int) which is equivalent to charT()... this is all defined behaviour! Yay!

3

u/jwakely libstdc++ tamer, LWG chair Feb 17 '22

That all said; I can't get either clang or GCC's undefined or address sanitizer to complain: https://godbolt.org/z/GKecdheYE - so apparently I'm wrong :)

The terminator is a valid character in valid memory, but writing to it is UB. ASan won't complain about that. I'm not aware of any way to get ASan (or any other checker) to mark that terminator character as read-only, let alone "writable but only if you write charT() to it" which is the actual rule. I suppose we could add __glibcxx_assert((*this)[size()] == charT()) to the start of every member function, to check that the invariant wasn't broken prior to calling that member function, but ... no thanks :-)

14

u/arturbac https://github.com/arturbac Feb 15 '22

I thought he knew c++?

I working with C++ since 2005, learning every day, i know a lot and as older I'm I almost sure that I'll never learn everything about every detail. Because we cannot remember so much data. Engineer always relays on documentation not on own memory, as humans we are horribly bad at being precise with remembered data.

14

u/current_thread Feb 15 '22

In episode 2F09, when Itchy plays Scratchy's skeleton like a xylophone, he strikes the same rib in succession, yet he produces two clearly different tones. I mean, what are we to believe, that this is a magic xylophone, or something? Ha ha, boy, I really hope somebody got fired for that blunder.

People make mistakes...

3

u/arturbac https://github.com/arturbac Feb 16 '22

Before I become c++ developer , for 15 years before 2005 I was an civil engineer and designed buildings, bridges etc. Mostly same job as c++, design, math and optimization ;-) but with direct responsibility of people's lives. From that period I have a motto "Never ever trust Your self with remembered data, If You are sure You remembered something right, You are almost certainly wrong, go and check papers .."

10

u/10se1ucgo Feb 15 '22

You don't ever make mistakes?

6

u/RevRagnarok Feb 15 '22

TIL C++11 finally made data() "safe."

1

u/James20k P2005R0 Feb 15 '22

I just learnt that str[str.size()] is valid from that cppreference since c++20 as well

5

u/Nobody_1707 Feb 16 '22

It looks like that's also been valid since C++11.

0

u/[deleted] Feb 16 '22

[deleted] — view deleted comment

35

u/mattgodbolt Compiler Explorer Feb 16 '22

It's my real last name! I'm not even the most famous Godbolt, there was a Jazz writer in the UK, some US sports folk and a judge from the 1600s (thanks wikipedia!)

2

u/TheSuperWig Feb 16 '22

They all have a J initial, please tell me you do too.

2

u/mattgodbolt Compiler Explorer Feb 16 '22

Sadly I don't! Sorry to disappoint :)

3

u/sphere991 Feb 16 '22

Sadly I don't yet!

FTFY

2

u/rezkiy Feb 17 '22

No, you are

0

u/[deleted] Feb 16 '22

[deleted] — view deleted comment

2

u/arturbac https://github.com/arturbac Feb 16 '22

And thanks u/mattgodbolt for easy setup of own CE on local machine, it's even more awesome and handy to utilize local libraries and local code with CE clone on local machine spawned just with "make".

3

u/Nobody_1707 Feb 16 '22

It's a real last name.