2 ms·
Holy shit, mind blown. I've done this before, but usually take modulo 8 rather than bitwise-and negative 7 as the final step.
by bitwize 12y ago
Holy shit, mind blown.
I've done this before, but usually take modulo 8 rather than bitwise-and negative 7 as the final step.
- nightcracker 12y agoDoesn't matter, any major compiler will transform this into an bitwise and.
- syncsynchalt 12y agoSame, I'd write it out using modulo and would assume the compiler would figure it out. void *p = x; p += 7; p -= (p%8); Now that I've written it out I suppose it's not any clearer than the mask method: void *p = x; p += 7; p &= ~7;
- deleted 12y ago[deleted]