X <<y>> z the order of evaluation in C

What is the evaluation order in C in the case x<<y>>z? Is (x<<y)>>zit due to associativity from left to right?

EDIT You need to know that the standards report this, and not know what happens when checking for a particular compiler.

+5
source share
5 answers

Online Project C 2011 (N1570)

6.5.7 Bitwise shift operators

Syntax

1 shift-expression:
          additive-expression
          shift-expression << additive-expression
          shift-expression >> additive-expression

The syntax indicates that both operators are left-associative, as shown below:

    x      <<       y         >>           z
    |               |         |            |
    +------ + ------+         |            |
            |                 |            |
            V                 |            V
      shift-expression        >>   additive-expression

+3

, >> << , x << y >> z (x << y) >> z.

+5

, , < → -.

+2

Yes, but I think it is safer to do this in 2 steps, for example x<<y, and then y>>zmake the compiler misinterpret a x<<y>>z. I have not used bitwise operations since all the time, but if I remember well what I said. I hope I helped you.

-1
source

All Articles