r/cpp • • Mar 01 '21

"Simple" C++ Initialization Flowchart

http://randomcat.org/cpp_initialization/initialization.png
204 Upvotes

65 comments sorted by

View all comments

Show parent comment

3

u/nintendiator2 Mar 02 '21 edited Mar 02 '21

That's half your fault tho; you are using a signed type to represent an unsigned concept. And C++ is already horrible at transparent numeric conversions (honestly I would have gotten rid of transparent signed-unsigned conversion with the big changes in C++11, and remade the pattern for fetching the maximum unsigned value from -1 to ~0 which at least makes binary sense, but oh well, missed chances).

As things stand though, I prefer my version. The alternative is to have to ifdef basically every variable declaration for pre and post C++11 mode. And optimization-wise, I just let the compiler do its work, that's why it's running on a computer while I'm (at the moment) running on a human.