I was using the __builtin_popcount
with clang compiler and I needed to count a 64 bit number (unsigned long long
or uint64_t
). From looking it up, __builtin_popcount
counts 16 bits, __builtin_popcountl
counts 32 bits, and __builtin_popcountll
counts 64 bits. When I tested it, __builtin_popcountl
was able to do calculations on 64 bit integers. Does anybody know the reason for this?
#include <iostream>
int main() {
unsigned long long bb = 0b1000000100000001000000010000000100000001000000010000000100000001;
std::cout << __builtin_popcountl(bb) << std::endl; //returns 9 (correct answer)
}