Note to self:
3 + 8 << 2
is not the same as
3 + (8 << 2)
That's an hour you just spent tracking down a bug based on a mistake you've made several times before.
Yes, I know, brackets. Normally I'm assiduous about brackets. But for short lines like, say,
3 + 8*2
I actually think they detract from readability.
I'm sure there are sound reasons why shift has precedence over addition in C, but I find it counter-intuitive in the extreme.
Maybe a nice dose of online mockery will help me remember in the future :(
Note to non-geeks:
Don't worry, not much to see here. I made a school-boy error.
3 + 8 << 2
is not the same as
3 + (8 << 2)
That's an hour you just spent tracking down a bug based on a mistake you've made several times before.
Yes, I know, brackets. Normally I'm assiduous about brackets. But for short lines like, say,
3 + 8*2
I actually think they detract from readability.
I'm sure there are sound reasons why shift has precedence over addition in C, but I find it counter-intuitive in the extreme.
Maybe a nice dose of online mockery will help me remember in the future :(
Note to non-geeks:
Don't worry, not much to see here. I made a school-boy error.
no subject
Date: 2010-07-12 03:24 pm (UTC)no subject
Date: 2010-07-12 03:44 pm (UTC)(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2010-07-12 05:12 pm (UTC)I have a natural defence against making this error, though. I am so bad at remembering precedence that the version of the line without parentheses reads like an error to me purely for not having them!
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2010-07-12 06:07 pm (UTC)(no subject)
From:(no subject)
From:If it isn't in BODMAS, be afraid.
Date: 2010-07-12 06:47 pm (UTC)I believe the logic is, twiddling bits is considered higher priority than assembling them into a bitmask. So build your mask, shift it into position, then OR the mask together.
Re: If it isn't in BODMAS, be afraid.
From:no subject
Date: 2010-07-13 12:47 pm (UTC)Then again, I'm mostly working with Access and VB ... so I can generate my own cockups.