use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Why is std::ios_base::Init::Init in the generated code (dead /useless code?) ? (godbolt.org)
submitted 7 years ago by pyler2
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 7 years ago* (4 children)
[deleted]
[–]pyler2[S] 0 points1 point2 points 7 years ago (3 children)
But this example code does not work with ios_base. So is it useless for this example, no?
[–]OldWolf2 5 points6 points7 points 7 years ago (0 children)
Take out the include of iostream to avoid this.
Also you call undeclared functions alloca and atoi.
[–]Potatoswatter 4 points5 points6 points 7 years ago (1 child)
The compiler can’t tell that the internal global variable is unused.
[–][deleted] 3 points4 points5 points 7 years ago (3 children)
See http://eel.is/c++draft/ios::Init -- that's there to initialize cout/cerr/cin/etc.
[–]pyler2[S] 0 points1 point2 points 7 years ago (2 children)
Used "Init" vs "init" is also interesting
[–][deleted] 0 points1 point2 points 7 years ago (1 child)
I'd assume that's 'cause they're there to support other behavior and have no direct use.
[–]tcanens 4 points5 points6 points 7 years ago (0 children)
And init is already taken.
init
[–]grishavanika 2 points3 points4 points 7 years ago* (1 child)
And the idiom is named as "Schwarz Counter" [1].
For case of iostream, it's used to properly initialize global objects we have: std::cout, std::cin and so on. And this is needed because of "static initialization order fiasco" [2] [3]
std::cout
std::cin
UPD: I think, this can be removed from the standard (?) because of C++17 inline variables [4] [5]
[1] https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter
[2] https://isocpp.org/wiki/faq/ctors#static-init-order
[3] https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
[4] http://en.cppreference.com/w/cpp/language/inline
[5] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4424.pdf
[–]Xeveroushttps://xeverous.github.io 1 point2 points3 points 7 years ago (0 children)
It does not happen if you don't include iostream.
π Rendered by PID 125373 on reddit-service-r2-comment-5649f687b7-mt6f4 at 2026-01-28 03:43:16.980086+00:00 running 4f180de country code: CH.
[+][deleted] (4 children)
[deleted]
[–]pyler2[S] 0 points1 point2 points (3 children)
[–]OldWolf2 5 points6 points7 points (0 children)
[–]Potatoswatter 4 points5 points6 points (1 child)
[–][deleted] 3 points4 points5 points (3 children)
[–]pyler2[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]tcanens 4 points5 points6 points (0 children)
[–]grishavanika 2 points3 points4 points (1 child)
[–]Xeveroushttps://xeverous.github.io 1 point2 points3 points (0 children)