The @ 2501 answer posted is absolutely correct, but does not explain why the standard requires an lvalue for post-increment. The main reason is that you need an lvalue (variable or memory location) for the post-increment in order to increment it.
When you apply p_Buf to the uint8_t* type, you created an rvalue in C. In simple terms, rvalues represent transient values that can be passed to functions assigned to variables, etc. Post-increment returns the original value, and then updates the variable or memory cell in which the value was stored, increasing it. Because they exist only during expression, rvalues cannot be updated, and post-increment cannot work on them. So the problem with
otherFunc (((uint8_t *)p_Buf)++);
is that ((uint8_t *)pBuf) is just an rvalue expression with no actual storage location. In fact, cast means that you only use the p_Buf value and no longer use the p_Buf variable p_Buf .
On the other hand, when you assign a cast to a variable:
p_Buf_8bit = (uint8_t *) p_Buf;
then the variable p_Buf_8bit is the value of l, which is a variable or memory cell. This can be post-incremented, which makes the statement in C quite correct:
otherFunc (p_Buf_8bit++);
source share