On 1/14/2017 7:05 AM, Paul wrote:
> The code assumes that int x = 7, y = f(x); is equivalent to
> int x = 7; int y = f(x);
>
> Are they in fact equivalent? Is it a rule of C++ that
> something1 , something2, ... always results in evaluating something1
> before something2 etc. etc ?
Yes, there is.
-------------------------------------------------------------------
8 Declarators [dcl.decl]
3 Each init-declarator in a declaration is analyzed separately as if it
was in a declaration by itself.(99
---
99) A declaration with several declarators is usually equivalent to the
corresponding sequence of declarations each with a single declarator.
That is
T D1, D2, ... Dn;
is usually equivalent to
T D1; T D2; ... T Dn;
where T is a decl-specifier-seq and each Di is an init-declarator. An
exception occurs when a name introduced by one of the declarators hides
a type name used by the decl-specifiers, so that when the same
decl-specifiers are used in a subsequent declaration, they do not have
the same meaning, as in
struct S ... ;
S S, T; // declare two instances of struct S
which is not equivalent to
struct S ... ;
S S;
S T; // error
Another exception occurs when T is auto (7.1.6.4), for example:
auto i = 1, j = 2.0; // error: deduced types for i and j do not match
as opposed to
auto i = 1; // OK: i deduced to have type int
auto j = 2.0; // OK: j deduced to have type double
-------------------------------------------------------------------
--
Best regards,
Andrey Tarasevich