Originally Posted by quzah
My fix was to switch from lcc-32 to gcc. It now recognizes shifts using variables denoting the amount to shift, shrinking my code by alot.
This is a discussion on Bitshift on 64-bit integers. within the C Programming forums, part of the General Programming Boards category; Originally Posted by quzah Code: uint64_t shift(uint64_t to_shift, int pos) { if( pos > 32 ) { to_shift <<= 32; ...
Originally Posted by quzah
My fix was to switch from lcc-32 to gcc. It now recognizes shifts using variables denoting the amount to shift, shrinking my code by alot.
I built the following with lcc-win32 and it generated the expected results. It shifted by an amount contained in a variable, and the amount could be greater than 32.Originally Posted by maththeorylvr
I'm only mentioning this because...Code:#include <stdio.h> #include <stdint.h> #include <inttypes.h> uint64_t shift(uint64_t value, int bits) { return value << bits; } int main( void ) { uint64_t value = ~0ULL; int bits; for ( bits = 0; bits < 64; ++bits ) { uint64_t result = shift(value, bits); printf("shift(%016"PRIx64", %2d) = %016"PRIx64"\n", value, bits, result); } return 0; }...I get nervous about blaming a compiler for my woes; more often there is something I missed in the original code. FWIW.Originally Posted by maththeorylvr
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*