Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

left shift error

Tags:

c++

c

I have an unsigned long long variable which is 8 bytes on my system which I'm trying to do the following on:

unsigned long long ull;
ull = timeLow;
ull |= timeHigh << 32;

I get a warning of: left shift count >= width of type when doing this. Also it doesn't seem to take into account the timeHigh shifted in. How do I fix this?

like image 253
user1620479 Avatar asked Feb 21 '26 10:02

user1620479


1 Answers

You're not shifting ull, you're shifiting timeHigh, and then storing the results of that shift in ull.

I suspect that timeHigh is not big enough to store the reults of a 32-bit shift. Make timeHigh an unsigned long long, (edit) or alternatively just assign timeHigh to ull and then shift that before or'ing in timeLow. (credit @JasonD)

like image 66
John Dibling Avatar answered Feb 24 '26 00:02

John Dibling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!