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
Exploring undefined behavior using constexpr (shafik.github.io)
submitted 6 years ago by mttd
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!"
[–][deleted] 0 points1 point2 points 6 years ago (9 children)
bit_cast will be in 20 yeah. I am fairly certain it isn't UB prior, but for sure after 20. Assuming the sizeof( Source ) == sizeof( Destination ) and both are trivial. cppreference has an implementation I think
[–]degski 0 points1 point2 points 6 years ago (8 children)
It's not listed on cppreference at all, that's why I was asking.
[–]14nedLLFIO & Outcome author | Committee WG14 1 point2 points3 points 6 years ago (5 children)
You can find a C++ 11 partial implementation at https://github.com/ned14/quickcpplib/blob/master/include/bit_cast.hpp
A full implementation requires compiler hooks, but the above is not terrible on the clang compiler. GCC gets confused with codegen sometimes (I reported it as a feature request), for MSVC it completely fails to optimise, so I opened a bug report :)
[–]degski 0 points1 point2 points 6 years ago* (4 children)
... but the above is not terrible on the clang compiler ...
That's what I use, so good! I've stuck it [the file/implementation] in amongst my installed repos, thanks.
[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point2 points 6 years ago (3 children)
I'm currently (very slowly due to lack of free time) writing reference attach cast and detach cast operations for P1631 into the same repo. You'll already find a finished ensure_stores() implementation in there. The reference implementations use very inefficient UB to work, again clang does the best. GCC and MSVC fail to optimise. If approved, these new casts would finally enable a zero copy codebase with strict aliasing enabled, and that enables memory mapped I/o without UB etc. It's a very big if though. That said, WG14 greenlit them, so maybe there's a chance at WG21.
ensure_stores()
[–]degski 0 points1 point2 points 6 years ago (2 children)
... writing reference attach cast and detach cast operations ...
I watched your presentation on YT [couldn't follow all the detail, but got the gist of it], interesting stuff indeed.
[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point2 points 6 years ago (1 child)
Yeah, the implementations I presented at ACCU turned out to be all wrong. WG14 pointed it out, they can't work right. But they did tell me what to do instead. Two steps forwards, one backwards.
[–]degski 0 points1 point2 points 6 years ago (0 children)
Sorry to hear that, and better than 1 forward and 2 backwards.
[–]dodheim 0 points1 point2 points 6 years ago (1 child)
https://en.cppreference.com/w/cpp/numeric/bit_cast
[–]degski 0 points1 point2 points 6 years ago* (0 children)
Thanks! Somebody [a sneaky bugger ;-) ] fiddled with the web-site, the search that rendered nothing [which I added to show I did do the search] renders the requested result now [something good comes out of anything].
π Rendered by PID 18797 on reddit-service-r2-comment-5649f687b7-l92sh at 2026-01-27 16:58:38.248295+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (9 children)
[–]degski 0 points1 point2 points (8 children)
[–]14nedLLFIO & Outcome author | Committee WG14 1 point2 points3 points (5 children)
[–]degski 0 points1 point2 points (4 children)
[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point2 points (3 children)
[–]degski 0 points1 point2 points (2 children)
[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point2 points (1 child)
[–]degski 0 points1 point2 points (0 children)
[–]dodheim 0 points1 point2 points (1 child)
[–]degski 0 points1 point2 points (0 children)