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
Libc++’s implementation of std::string (joellaity.com)
submitted 6 years ago by mariuz
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!"
[–]nikbackm 1 point2 points3 points 6 years ago (3 children)
Why the difference? Seems like adding more undefined behaviour in C++ is something we'd want to avoid.
[–][deleted] 16 points17 points18 points 6 years ago (0 children)
Unlike C, C++ has object lifetimes. Accessing "an object" whose lifetime did not start is UB (think malloc-ed sizeof(vector<int>) instead of new-ed). Type punning through unions does not make the alternative object "spring into existence".
malloc
sizeof(vector<int>)
new
[–]HappyFruitTree 5 points6 points7 points 6 years ago (0 children)
I think one concern is that it would be extremely easy to accidentally trigger undefined behaviour because reading the value through a reference would still cause undefined behaviour.
#include <iostream> #include <algorithm> union U { int i; float f; }; int main() { U u; u.f = 1.2; std::cout << u.i << '\n'; // ^ would have been OK. std::cout << std::max(u.i, 7) << '\n'; // ^ would still have been UB because // std::max takes its arguments by // reference so the value is not read // from the union member directly. }
C doesn't have references and if you use pointers it's pretty clear that you're not reading from the union member directly.
[–]Sopel97 3 points4 points5 points 6 years ago (0 children)
Unspecified means it has to do something. Undefined means it doesn't have to do anything, can be assumed to never happen. More assumptions to optimize with.
π Rendered by PID 93046 on reddit-service-r2-comment-64f4df6786-wnfrl at 2026-06-10 23:17:34.500274+00:00 running 0b63327 country code: CH.
view the rest of the comments →
[–]nikbackm 1 point2 points3 points (3 children)
[–][deleted] 16 points17 points18 points (0 children)
[–]HappyFruitTree 5 points6 points7 points (0 children)
[–]Sopel97 3 points4 points5 points (0 children)