venta: (Default)
[personal profile] venta
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.

If it isn't in BODMAS, be afraid.

Date: 2010-07-12 06:47 pm (UTC)
From: [identity profile] fractalgeek.livejournal.com
Brackets are your friend.

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.
Edited Date: 2010-07-12 09:17 pm (UTC)

Re: If it isn't in BODMAS, be afraid.

Date: 2010-07-13 10:41 am (UTC)
From: [identity profile] venta.livejournal.com
You see, if I remembered that it wasn't BODMAS, there wouldn't be a problem :) As far as I'm concered << and * are basically the same operation, making it an M.

Profile

venta: (Default)
venta

December 2025

S M T W T F S
 123456
78910111213
14151617181920
212223 24252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 27th, 2025 11:36 pm
Powered by Dreamwidth Studios