I just got back from CppCon 2018 in Bellevue Washington. And since this is a podcast where I teach you how to program, I thought I’d share something that I learned at the conference.
It was a great conference with full days that went from 8 in the morning to usually 10:30 at night for five straight days. And then there were classes before and after the conference. There were so many choices for presentations to attend that it was tough to choose. It was packed with people. I think there were over 1,200 people attending. But at the same time, it was as smooth as you can imagine. The organizers deserve amazing credits. Even with all the people, I never had trouble finding a good spot. Sometimes I would sit up front. And sometimes I would sit at a table in the back of the room.
One of my favorite talks was from Nicolai Josuttis. This is something that I’ve been aware of since I first started programming C++. There’s a lot of different ways to declare a variable and initialize that variable so it has a value.
This explanation really needs text for you to be able to see the actual code. So I won’t be able to describe everything from the presentation. I’ll stick to the big ideas. In a couple weeks, more or less, you should be able to watch the full presentation on YouTube. It’s called “The Nightmare of Initialization in C++”.
Probably the main thing to understand is that in C++ if you have a method that declares an int variable and gives that variable a name, then the value of that variable is undefined until you write a value first. If you just declare a variable and read from it without first providing a value, then you’re in undefined behavior. The value could be anything.
The rules are changing all the time. Some of the things I learned from this talk were about how things change in C++17 vs. earlier versions of the language. You’ll also gain insight into some changes that might take effect in C++20. Listen to the full episode to learn more and make sure to watch the video once it’s published.