Re: Function call evaluation order



Frederico Pissarra wrote:
"Carl Daniel [VC++ MVP]"
The problem that precedence alone doesn't cover is that the relative
order of evaluation of the arguments of the three function calls is
not defined, nor is whether the evaluation of those arguments
overlaps.

Still... In the last example I show to you, here is the assembly
generated by compiling without optimizations (cl -Od -FAs -Fa -c
test.c) - of course the code sintax is a little more complex than
that... but it shows pos and pre increment in action...

You missed the point entirely - there's no issue here with understanding of
pre- and post-increment.

Code like the example that started this thread:

s.assign(data[i++]).append(data[i++]).append(data[i++]);

has undefined behavior.

Yes, it may do exactly what you hope it does, but it's not required to, and
there are reasonable code generation sequences where it does something
nearly opposite to what you expected.

-cd


.



Relevant Pages

  • Re: C FAQ 3.1
    ... I am convinced we have undefined behavior because ... > favour left to right evaluation of arguments, on another ot might be right ... With OOE processors and write-back memory caching, ... Should C compilers be forced to insert memory ...
    (comp.lang.c)
  • Re: Does this program exhibit undefined behaviour or output?
    ... thearg got progname ... Yes, the order of evaluation of arguments is not specified, so at the ... the order of argument evaluation without invoking undefined behavior. ...
    (comp.lang.c)
  • Re: C FAQ 3.1
    ... >> ccwork wrote: ... I am convinced we have undefined behavior because ... optimisation. ... favour left to right evaluation of arguments, on another ot might be right ...
    (comp.lang.c)
  • Re: C FAQ 3.1
    ... Regardless of the order of evaluation, ... Expressions ... It would only add to your confusion. ... Code which exhibits undefined behavior like that, ...
    (comp.lang.c)
  • sequence points and evaluation order
    ... Expression has undefined behavior (left operand uses errno, ... Code has unspecified behavior. ... different places not separated by a sequence point constraining evaluation ... Can t2num be assigned the value ...
    (comp.lang.c)