Difference between the prefix / postfix increase in the Objective-C method call?

advertisements

I understand the difference between prefix and postfix notation in plain C.

I was, however, wondering if the same rules applied to Objective-C method calls like

[myObject foo:++i];

and

[myObject foo:i++];

Or is the "inner C expression" always evaluated first, the two method calls thus yielding the same result?


Yes, the same rules apply. Obj-c is a strict superset of c so all things that work in c will work the exact same in Objective-c.

++i

Will increment i before the method is called so those 2 methods will not yield the same result (assuming, or course, that the result depends on the value of i). One is called after i is incremented, the other is called before.