-1

can I use post-increment in a function return in C like this?

int meta_solve() {    
  //some codes
  return metaData[head++]; //head is global variable
}

I asking this question because it showing the different results on windows and mac. thanks for your attention. have a great day!

1 Answers1

2

Yes, that will work.

The return will not happen until the expression metaData[head++] is fully evaluated so the (global) variable head is incremented before the function returns.

Support Ukraine
  • 42,271
  • 4
  • 38
  • 63
  • Actually, it is a defect in the C standard that nothing in the normative text states there is a sequence point after a `return` statement. Theoretically, the increment is allowed to happen after the function returns. If the call is inside a larger expression , the increment may not be sequenced with respect to other things in the expression. – Eric Postpischil Jun 05 '21 at 19:42