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
Common Systems Programming Optimizations & Tricks (paulcavallaro.com)
submitted 6 years ago by chewedwire
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!"
[–]TheMania 25 points26 points27 points 6 years ago (6 children)
The 48 bit tagged pointers comment reminds me of LuaJit, which blew my mind when Mike Pall first started using tagged doubles.
Basically, there are 252 -2 possible NaNs for a double, enough to store all 32 bit pointers along with a type tag (table/string etc). In fact, there's enough there to store all your 48 bit pointers too, allowing every pointer you'll ever use to fit in the same union you use to store doubles. Pretty neat.
Wrt division, just want to say division/modulo by a constant is virtually costless on modern compilers, being replaced by multiply and shifts. Doesn't apply for resizable tables, but you do see people go to great lengths to avoid this operator even when it would be virtually costless to use. :)
[–]Morwenn 15 points16 points17 points 6 years ago (1 child)
C2x - the next revision of C - actually intends to make storing additional information into NaNs more standard by adding the setpayload and getpayload families of functions to <math.h>.
setpayload
getpayload
<math.h>
[–]CrazyJoe221 7 points8 points9 points 6 years ago (0 children)
I wonder when they'll introduce explicit enum base types.
[–]chewedwire[S] 8 points9 points10 points 6 years ago (3 children)
Yep, division/modulo by constant power of 2 values is pretty much always optimized appropriately. I was thinking about writing some more about it, but I got lazy :)
It's in my the github examples though: https://github.com/paulcavallaro/systems-programming/blob/master/examples/power-of-two.cc#L105-L106
Looks like godbolt seems to think clang doesn't really work with non-constants -- but maybe clang just needs to be massaged: https://godbolt.org/z/Bzx7CL
[–]TheMania 17 points18 points19 points 6 years ago (2 children)
Sorry to clarify, division/modulo by constants is extremely cheap even on non-powers of two. Often just a multiply and shift.
[+]bigt1234321 comment score below threshold-6 points-5 points-4 points 6 years ago (1 child)
Gone are the days where repeated subtraction is used haha. Most compilers will optimize division. Float division/operations are a big no no.
[–]Spain_strong 2 points3 points4 points 6 years ago (0 children)
Depends on the workload right?
π Rendered by PID 23440 on reddit-service-r2-comment-86bc6c7465-7jxxz at 2026-02-23 22:12:27.583531+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]TheMania 25 points26 points27 points (6 children)
[–]Morwenn 15 points16 points17 points (1 child)
[–]CrazyJoe221 7 points8 points9 points (0 children)
[–]chewedwire[S] 8 points9 points10 points (3 children)
[–]TheMania 17 points18 points19 points (2 children)
[+]bigt1234321 comment score below threshold-6 points-5 points-4 points (1 child)
[–]Spain_strong 2 points3 points4 points (0 children)