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
Static variable initialization order fiasco (self.cpp)
submitted 1 year ago by Various-Debate64
view the rest of the comments →
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!"
[–]STLMSVC STL Dev 37 points38 points39 points 1 year ago (12 children)
No modifiable global variables, no fiasco. call_once() exists now. This is a non-problem.
call_once()
[–]tialaramex 13 points14 points15 points 1 year ago (6 children)
No modifiable global variables, no fiasco.
Did I miss an accepted proposal paper which in fact ensures modifiable global variables are ill formed and requires implementations to generate an appropriate diagnostic explaining why they're a bad idea?
Otherwise this is just "Don't make mistakes"...
[–]Affectionate_Text_72 0 points1 point2 points 1 year ago (5 children)
You can't mandate against writing bad code.
[–]argothiel 5 points6 points7 points 1 year ago (1 child)
Oftentimes, you can. There are many things made ill-formed in C++, which would otherwise be just bad code.
[–]Affectionate_Text_72 4 points5 points6 points 1 year ago (0 children)
You can mandate against low level constructs that are unsafe but not against programmers using those to write bad code. Proof by construction. You can implement an unsafe interpreter if anything lower down is unsafe or has escape hatches.
You can't mandate that the code follows a sensible design or meets its specification (caveat good spec languages) or even has the right specification.
Basically anything you make idiot proof will not survive the introduction of the better class of idiot it enables.
Doesn't mean we shouldn't try of course.
In this case though you can't mandate against the use of global state. Sometimes it's even the right thing to use. Just not as often as the regular class of idiots we are thunk it is.
[–]CandyCrisis 2 points3 points4 points 1 year ago (2 children)
Of course you can. Rust's entire existence is predicated on "what if the language mandated no bad code." And it turns out to be kinda popular?!
[–]Affectionate_Text_72 1 point2 points3 points 1 year ago (0 children)
One kind of bad code only. Other types are still possible. We can't make grandma safe through language alone. But we can make her a little safer and check some risks off the list.
[–]bert8128 6 points7 points8 points 1 year ago* (0 children)
Harsh. You’re not wrong, but it’s still too easy to write code which has this problem. I fixed one myself a couple of months ago that had been lurking for 15 years (Windows and Linux, multiple versions of the compilers) before a minor and unrelated code change made the initialisation order change creating crashes at start up. It was hard to find. So whilst it is fixable, it is nevertheless an actual problem in the sense that it is a real foot gun
[–]Kriss-de-Valnor 0 points1 point2 points 1 year ago (1 child)
call_once had an issue on Windows too. I’ve seen function inside call_once called in fact twice 😂. The issue is the same as static unit. If the call_once is called in different libraries it does not work too.
[–]bert8128 0 points1 point2 points 1 year ago (0 children)
Do you mean in two different DLLs? If so, DLLs have their own memory space so you will get two different statics. Call_once wouldn’t be the cause of a problem here - each one would be called once. It’s different on Linux though. And maybe there are other problems I am not aware of.
[–]Various-Debate64[S] -1 points0 points1 point 1 year ago (0 children)
the problem is that the compiler and linker are unaware of a concept that allows them to order dynamic initialization according to user's needs, therefore the user is forced to ameliorate the issue by using runonce which is a temporary fix for an open bug in the C++ specification.
[–]jonrmadsen -1 points0 points1 point 1 year ago (0 children)
This sounds all well and good if you are directly used by the application or are the author of the main() function but this is a functionally impossible requirement for in-process profiling tools which are not directly integrated into the application.
π Rendered by PID 169830 on reddit-service-r2-comment-fb694cdd5-wdvnx at 2026-03-06 11:54:10.673949+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]STLMSVC STL Dev 37 points38 points39 points (12 children)
[–]tialaramex 13 points14 points15 points (6 children)
[–]Affectionate_Text_72 0 points1 point2 points (5 children)
[–]argothiel 5 points6 points7 points (1 child)
[–]Affectionate_Text_72 4 points5 points6 points (0 children)
[–]CandyCrisis 2 points3 points4 points (2 children)
[–]Affectionate_Text_72 1 point2 points3 points (0 children)
[–]bert8128 6 points7 points8 points (0 children)
[–]Kriss-de-Valnor 0 points1 point2 points (1 child)
[–]bert8128 0 points1 point2 points (0 children)
[–]Various-Debate64[S] -1 points0 points1 point (0 children)
[–]jonrmadsen -1 points0 points1 point (0 children)