Re: order of evaluation

From: msalters (Michiel.Salters_at_logicacmg.com)
Date: 02/15/05


Date: 15 Feb 2005 04:56:06 -0800


Sumit Rajan wrote:
> "ASobol" <sobol@mccme.ru> wrote in message
> news:1108466861.501664.262270@o13g2000cwo.googlegroups.com...
> > //code.begin()
> > #include <iostream>
> >
> > int g (int i)
> > {
> > static const int j = i;
> > return j;
> > }
> >
> > int main (int, char**)
> > {
> > std::cout << g(0) << g(1) << g (2) << g(3);
>
> The compiler is allowed to determine the order in which the 4 calls
to g()
> are executed.

Yes, but it may not execute them concurrently (unless you cannot detect
it, of course. "as if"-rule ). One call must be made first. It may be a
different choice on every run, though.

> > Is output of this program undefined due to C++ standart?
>
> Undefined behaviour.

Wrong, unspecified. There are proper sequence points between the
calls, the only thing unspecified is the order of sequence points.
No variable is modified twice between sequence points. In fact,
the only variable modified is static const int j, which by
definition cannot be modified twice at all.

Regards,
Michiel Salters



Relevant Pages

  • Re: instruction re-ordering
    ... Is an ANSI C compliant compiler authorized to re-order L2 and L3, ... execute the following sequence instead: ...
    (comp.lang.c)
  • What does Cypriene stop so freely, whenever Haron carves the puzzled resistance very close?
    ... filter depending on the sequence. ... I'll reassure weakly or Zephram will allow the ... Alhadin won't execute any ... Gul differs the ghost ...
    (sci.crypt)
  • Re: Calling All Pirates...
    ... executable on disk and then searches for the first keyboard input sequence. ... Then execute the program at that point and drop out of memory. ...
    (comp.sys.cbm)
  • RE: Best Way to Auto Increment with Oracle
    ... to fetch a sequence, so you issue 'select seq.nextval from dual'. ... The statement is executed and the fetch occurs. ... You then execute the insert statement. ... my previous mail in this thread), so with or without the trigger, you ...
    (perl.dbi.users)
  • Re: ThreadPool wait for threads to finish
    ... >> If you want to execute them in sequence what you need to make a thread ... > can't actually complete the request until all the separate queries are ... requests while I process a large batch of documents. ...
    (microsoft.public.dotnet.languages.csharp)