Originally Posted by
maththeorylvr
but uint_64 doesnt shift correctly when I try to use a variable to represent the number of bits to shift
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.
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'm only mentioning this because...
Originally Posted by
maththeorylvr
My fix was to switch from lcc-32 to gcc. It now recognizes shifts using variables denoting the amount to shift
...I get nervous about blaming a compiler for my woes; more often there is something I missed in the original code. FWIW.