I'm reading from a byte array as follows:
int* i = (int*)p;
id = *i;
i++;
correct me if I'm wrong, but ++ has precedence over *, so is possible to combine the *i and i++ in the same statement? (e.g. *i++)
(this is technically unsafe C#, not C++, p is a byte*)
I believe that
and
are equivalent.
The
++
operator, when used as a suffix (e.g.i++
), returns the value of the variable prior to the increment.I'm somewhat confused by the reflector output for
which comes out as
and
which clearly are not equivalent.
id = *i++
will do what you want.
++ modifies the pointer after the dereference.
EDIT: As Eric points out, per the spec, ++ does not happen after dereference. i++ increments i and return its initial value, so the spec defined behavior is the increment happens prior to dereference. The visible behavior of id = *i++ is the same whether you view the increment happening before or after dereference.