3

in Linux kernel source code, I find below code:

    h++;
    pending >>= 1;

It is part of __do_softirq(void). But what does ">>=" mean? Why isn't it ">>" as I remember? Thanks!

0

2 Answers 2

16

It simply does

pending = pending >>1;

In short it divides by 2 an unsigned int.

That's the same construct than +=, /=, etc.

It's not just pending >>1 as you remember because that wouldn't store the result of the shift operation in the variable.

Sign up to request clarification or add additional context in comments.

4 Comments

It divides by 2 an unsigned int. C does not specify what happens to a signed int. You're better off using /= in that case.
yes. precision added. I don't think this construct for dividing by two is really useful today as all compilers probably optimize the /=2 on unsigned int. You should probably use it mainly when you use the int to store bits.
@DougCurrie you mean for a negative signed integer.
Thank you for detailed explaination of the "="! I leanrt it.
1

It's equivalent to

pending = pending >> 1;

Which bitshifts right the bits in pending. This would have the effect of dividing an unsigned int by 2. >> and << are the bitshift operators, and the combination with = behaves the same way += and /= do.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.