3 ms·
> It's not operator precedence—that's a separate issue > It's even mnemonic—when the increment symbol goes before the thing being incremented, the increment ha
by cellularmitosis 6y ago
> It's not operator precedence—that's a separate issue
> It's even mnemonic—when the increment symbol goes before the thing being incremented, the increment happens first; else after—but even if not, it's a fairly basic language feature.
I think you missed the issue.
This is 100% about operator precedence, and has nothing to do with the decrement operator being in front of or behind the variable.
This expression:
*stack--
means either this:
(*stack)--
or this:
*(stack--)
depending on the operator precedence rules.
If this is the layout of memory:
~~~~~~
stack-1: | 52 |
stack: | 23 |
stack+1: | 19 |
~~~~~~
(* stack)-- evaluates to 22, while *(stack--) evaluates to 52.
https://godbolt.org/z/P7Ghfc https://godbolt.org/z/P7Ghfc
- moonchild 6y ago> operator precedence Right, yes. I got confused by your example, because the example is definitely about pre- vs post-increment. My point about idioms still stands, though. > (* stack)-- evaluates to 22, while * (stack--) evaluates to 52. Actually, (* stack)-- evaluates to 23, but changes *stack to 22 :)
- cellularmitosis 6y ago> Actually, (* stack)-- evaluates to 23, but changes *stack to 22 :) Thanks, I just realized I had that wrong :) https://pastebin.com/n7sHzW3p https://pastebin.com/n7sHzW3p