Thread View: comp.std.c++
2 messages
2 total messages
Started by Bernd Anhaeupl
Mon, 22 Jan 1996 16:39
order of evaluation
Author: Bernd Anhaeupl
Date: Mon, 22 Jan 1996 16:39
Date: Mon, 22 Jan 1996 16:39
50 lines
2460 bytes
2460 bytes
In various places the DWP specifies, that the order of evaluation of
some expressions is unspecified.
Some questions:
1.) Does this mean, that for example in the following function call
f(a(...),b(....),c(....));
a(...), b(...), c(...) may even be evaluated in parallel in a
multitasking environment?
1a) Is a statement like the one above valid C++, if a(), b()
and c() are using and modifying the same global variables
--- What is the exact meaning of "sequence point" in section 5
paragraph 4 of the april DWP in this context?
static global_variable;
int a(){.....; global_variable++; .....}
int b(){.....; global_variable++; .....}
int c(){.....; global_variable++; .....}
Please think of the consequences. Even such basic operations
like free store management (User defined operator new,...!)
will access and modify global data (structures).
2.) Is it legal for a compiler to reorder the evaluation of
the operator new and the constructor calls of some new expressions.
For example, is it legal for a compiler to evaluate
f(new a(new b())) or f2(new a, new b) (see also question 1)
in the following order:
tmp1=a::new(sizeof(a)); tmp1=a::new(sizeof(a))
tmp2=b::new(sizeof(b)); tmp2=b::new(sizeof(b))
tmp2.b(); tmp1.a()
tmp1.a(tmp2); tmp2.b()
f(tmp1); f2(tmp1,tmp2);
--
Bernd Anhaeupl Tel.: +49 9131 857787
LATE - Uni Erlangen
Cauerstr. 7 Email: anhaeupl@late.e-technik.uni-erlangen.de
91058 Erlangen
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: order of evaluation
Author: Steve Clamage
Date: Mon, 22 Jan 1996 17:22
Date: Mon, 22 Jan 1996 17:22
43 lines
2332 bytes
2332 bytes
In article aul@rznews.rrze.uni-erlangen.de, anhaeupl@late.e-technik.uni-erlangen.de (Bernd Anhaeupl) writes: >In various places the DWP specifies, that the order of evaluation of >some expressions is unspecified. >1.) Does this mean, that for example in the following function call > > f(a(...),b(....),c(....)); > > a(...), b(...), c(...) may even be evaluated in parallel in a > multitasking environment? No. Section 1.8 says function calls may not be interleaved. In your example, "a", "b", and "c" may be called in any order, but whichever one is called first must complete before the second one is called. (The C++ language definition does not address parallelizing of program execution, but we can talk about interleaving parts of expressions.) >2.) Is it legal for a compiler to reorder the evaluation of > the operator new and the constructor calls of some new expressions. > For example, is it legal for a compiler to evaluate > f(new a(new b())) or f2(new a, new b) (see also question 1) > > in the following order: > tmp1=a::new(sizeof(a)); tmp1=a::new(sizeof(a)) > tmp2=b::new(sizeof(b)); tmp2=b::new(sizeof(b)) > tmp2.b(); tmp1.a() > tmp1.a(tmp2); tmp2.b() > f(tmp1); f2(tmp1,tmp2); I believe the reordering is allowed, because I don't think there is any sequence point that prevents it. --- Steve Clamage, stephen.clamage@eng.sun.com [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads