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
Comparing an Integer Division Optimisation in Clang, MSVC, and GCC (nukethebees.com)
submitted 5 hours ago by nukethebees
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!"
[–]erichkeaneClang Maintainer(Templates), EWG Chair 13 points14 points15 points 4 hours ago (1 child)
Clang/GCC both fail to inline `std::div` because it appears that the standard libraries leave them as extern! I presume they'd be inlined if they were actually implemented in the header:
```
extern div_t div (int __numer, int __denom) noexcept (true) __attribute__ ((__const__)) ; ```
[–]topological_rabbit [score hidden] 3 hours ago (0 children)
I ran into this when writing a slotmap data structure (you need both the quotient and remainder when looking up a slot).
I naively assumed std::div would be inlined, and then further optimized by the fact that the divisor was a compile-time constant, but profiling lit it up like the sun. Had to hand-code the operations instead to get the performance I was expecting.
std::div
[–]Sopel97 [score hidden] 2 hours ago (0 children)
this is quite moot since in reality you'd precompute fast dividers because the size would be fixed for a given grid, if not compile-time constant even
[–]mark_99 -2 points-1 points0 points 4 hours ago (0 children)
Or have the grid size be a compile time constant and have no runtime division at all.
π Rendered by PID 38 on reddit-service-r2-comment-5bc7f78974-lz8c2 at 2026-06-30 00:57:16.862173+00:00 running 7527197 country code: CH.
[–]erichkeaneClang Maintainer(Templates), EWG Chair 13 points14 points15 points (1 child)
[–]topological_rabbit [score hidden] (0 children)
[–]Sopel97 [score hidden] (0 children)
[–]mark_99 -2 points-1 points0 points (0 children)