Yes, actually. Mainly library members, though, it's rare that a language feature will be deprecated because they don't want to risk breaking very important 20-year-old unmaintained libraries that the entirety of modern infrastructure depends on. (It's a meme, but we meme about it because it's true.)
The most notable one is dynamic exception lists (throw(whatever) in the function signature), which got deprecated and mostly removed because nobody ever cared enough to actually support it. It was on life support for a while, where the "throws nothing" version (the only one that ended up being not worthless) is a synonym for noexcept, and every other throw-list is dead, before it got the boot too in C++20 or so. And similarly, the most notable library feature is probably "good" old std::auto_ptr, which got deprecated in C++11 because it was kinda really bad and unique_ptr was better, and finally got the boot in C++17.
Apart from that... it's hard to find a good list online, really. There's a partial list here, but you'd probably have to scour the various standards to find something more complete.
Now, that said, being deprecated (or even removed) doesn't mean that compiler vendors actually listen, because they're the ones that have to actually support all those ancient legacy codebases. Especially if the compiler includes version switches. If a compiler includes, e.g., both -std=c++11 and -std=c++17, then it will never remove features that were removed in C++17; it can disable them for -std=c++17 mode, but it still needs to be able to provide them for -std=c++11 mode.
So what it ultimately boils down to is that the language tries to deprecate & remove things, but legacy code is holding the compilers hostage.
Eh... not really, weirdly enough. Some of them are just the same thing in different places and/or contexts (e.g., "copy initialisation", "constant initialisation", "initialisation with auto", "in-class member initialisers" & "constructor member initialiser list", and "if/switch init-statements" are all the same feature in different contexts), and most of the others do different things under the hood (e.g., constructor delegation allows you to chain constructors, default initialisation lets you use the type's base rules, copy initialisation duplicates another object (or is optimised into direct optimisation if possible), direct initialisation hard-codes into the executable, zero initialisation sanitises memory, reference initialisation is singled out because it either registers a second name or creates a pointer, etc..).
It's a case where the language makes it look more complex than it actually is... which, admittedly, happens a lot in C++. Most of these really just boil down to "how Type t = val; works depends on what Type is", more than anything else.
Besides one or two, almost all of these are doing entirely different things, or are entirely distinct syntaxes to begin with.
For example, these two are the exact same declaration: - int x; - static int x;
The latter just declares a variable with internal linkage (assuming the value is at global scope). The rules related to initialization for such declarations are irrelevant since you’re still declaring the same thing. You can remove ‘static’ altogether.
It becomes very difficult to take many criticisms of the language seriously when it’s clear that most of the people making them seem to have never touched the language or tried to understand any of it.
Inside a function body, I assume static int x; is like C and will declare storage with static lifetime; that is, it persists between function calls.
Also, in the case of int x; in function body scope, does C++ initialize x to 0 by default? C certainly wouldn't (instead, x would be uninitialized), but I don't really know C++.
For the second, it is also uninitialized in C++. This is the case for any primitive type (compound/composite/custom types can be default- or zero-initialized through implicit constructor calls with the same syntax).
You can just zero-initialize the variable by appending a pair of braces, which I do with every variable I don’t care to explicitly initialize: int x{};
There are a few contexts where x would be zero-initialised (mainly related to classes (structs with their helper functions built into them so they don't pollute the global namespace), IIRC), but it's usually the same as C.
On that note, though, one of the things C++26 will change once it's officialised (or has changed, if it already is) is that reading uninitialised variables is now an error instead of UB, to prevent compilers from ignoring pre-assignment reads. Creation still works fine, it's just reading that gets changed. (And you can keep the old behaviour by declaring the variable [[uninitialized]], if needed/desired.)
I'm really glad to work with Go these days. Is it a perfect language? Far from it. But it's such a relatively straightforward and unsurprising language. Very readable and predictable. Makes it easy to work with.
I still do appreciate more complex languages for the beautiful abstractions you can make, but especially as I read code more than I write it (and even more so with AI), Go's readability makes it perfect.
View all comments
265
u/SamG101_ 13d ago •
Pooh needs about 50 more faces, for the 50 ways to initialise a variable in c++
https://leanpub.com/cppinitbook 300 odd pages
obligatory and thats just initialisation not assignment 💀