I like Orion's responses. I'll add two things:
- The left-to-right still applies first
- The inner-to-outer to ensure that all arguments are resolved before calling the function
Say we have the following example:
a = Foo(5, GetSummary("Orion", GetAddress("Orion")),
GetSummary("Chris", GetAddress("Chris")));
Here's the order of execution:
GetAddress("Orion")
GetSummary("Orion", ...)
GetAddress("Chris")
GetSummary("Chris", ...)
Foo(...)
- Assigns to
a
I can't speak about C#'s legal requirements (although I did test a similar example using Mono before writing this post), but this order is guaranteed in Java.
And just for completeness (since this is a language-agnostic thread as well), there are languages like C and C++, where the order is not guaranteed unless there is a sequence point. References: 1, 2. In answering the thread's question, however, &&
and ||
are sequence points in C++ (unless overloaded; also see OJ's excellent answer). So some examples:
foo() && bar()
foo() & bar()
In the &&
case, foo()
is guaranteed to run before bar()
(if the latter is run at all), since &&
is a sequence point. In the &
case, no such guarantee is made (in C and C++), and indeed bar()
can run before foo()
, or vice versa.