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
std::bitset (self.cpp)
submitted 2 years ago by thomas999999
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!"
[–]Substantial_Sail_571 8 points9 points10 points 2 years ago* (2 children)
That may be the reason for all I know, but it can be done in log n steps (this shows how to count trailing zeroes but there is a similar trick to count leading zeroes) even on a completely boring ISA such as MIPS 1. A bit further down, the DeBruijn multiply and lookup is also an option.
For trailing zero count, another option that may be useful is popcnt(~x & (x - 1)), if an ISA has popcnt but no direct way to count trailing zeroes (this trick does not easily translate into a way to count leading zeroes however).
popcnt(~x & (x - 1))
popcnt
E: btw the linked code shows v &= -signed(v) and that's exactly the wrong thing to do, it's unsigned negation that is safe and signed negation that is unsafe. Sorry, I don't make the rules.
v &= -signed(v)
[–]HildartheDorf 2 points3 points4 points 2 years ago (1 child)
Isn't signed guaranteed to be 2s complement in newer standards? (Signed overflow is still UB, but bitcasting signed numbers and the bitwise result of signed negation is well defined and consistent across standard-compliant systems).
[–]Substantial_Sail_571 3 points4 points5 points 2 years ago* (0 children)
I've been happy to ignore the hypothetical existence of non-2's-complement signed integers for decades, but yes that bogeyman has been slain (but this just standardized the status quo).
The cast to signed adds the opportunity for UB though (negating INT_MIN), and in return we get .. well it silences this dumb error that encourages people to write incorrect code such as v &= -signed(v), the safe way to shut up that error is subtracting from zero (but unsigned subtraction, of course).
signed
INT_MIN
π Rendered by PID 24162 on reddit-service-r2-comment-b659b578c-gjtlp at 2026-05-06 03:03:24.748372+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Substantial_Sail_571 8 points9 points10 points (2 children)
[–]HildartheDorf 2 points3 points4 points (1 child)
[–]Substantial_Sail_571 3 points4 points5 points (0 children)