The order of operations in C. ++ vs | = which occurs first?

I have the following code that I am reading:

if( (i%2) == 0 ){ 
    *d = ((b & 0x0F) << 4); 
}
else{
    *d++ |= (b & 0x0F); 
};

I look specifically at the instructions elseand wonder in what order is this happening? I do not have a regular C compiler, so I cannot verify this. When we perform *d++ |= (b & 0x0F);, what order does this happen in?

+5
source share
8 answers

++ is applied to the index d, not an lvalue, which is assigned, *d.

If you really want this, you can think of it this way:

  • bBitwise-AND: ed value with constant0x0f
  • The resulting bit is bitwise OR: ed to a value that dpoints to.
  • d , .
+11

d ++ d , . *, - , | =. , d (b 0x0F) .

, , , . , C! .

*d |= (b & 0x0F); 
d++;
+5

|=, *d |=, d . , , , .

+2

++ |=. .

+2

( ++) .

0

++ . - (.. d++ ) (temp=d, d++, temp).

0
0

*d++ |= (b & 0x0F) :

  • *d++ b & 0x0F (, , ; b & 0x0F *d++, );
  • (b & 0x0F) *d++;
  • , d;
  • - d.

The expression is *d++parsed as *(d++); those. you dereference the result of an expression d++. The expression d++evaluates the current value d, and at some undefined point before the next point in the sequence (in this case, at the end of the instruction), the value is updated d. The side effect of the update dshould not be applied immediately; this may occur before or after the appointment.

0
source

All Articles