The first example is still an expression to me |
|
|
From the way Disch explained it, it sounded like no possible way it could be defined to always be true. Is there a variation of that that isn't defined? |
a++ + a++
is undefined. There can't be more than one operation with side effects performed on a single variable without a sequence point in between them. For example, && and , introduce sequence points, but + doesn't.
|
|
|
|
6 |
helios wrote: |
---|
Nope. Initialization syntax doesn't form an expression, it forms a list of comma-separated expressions. Like this (BNF follows): |
|
|
|
|
|
|
Volatile Pulse wrote: |
---|
int a = 0; a ++ + ++ a * ++ a; // Evaluates to |
Volatile Pulse wrote: | ||||
---|---|---|---|---|
I say they're an expression (again the wrong word, but broken down, I look at it like this:
|
Similarly:
|
|
|
|
|
int a = b, c, d;
it could be rewritten as:
|
|
cire wrote: | ||
---|---|---|
In the case of int a = b, c, d; it could be rewritten as:
[Edit: Making the assumption that b, c, and d were previously defined.] |
|
|
C:\Programming\Test3\main.cpp||In function 'int main()':| C:\Programming\Test3\main.cpp|5|error: redeclaration of 'int c'| C:\Programming\Test3\main.cpp|4|error: 'int c' previously declared here| C:\Programming\Test3\main.cpp|5|error: redeclaration of 'int d'| C:\Programming\Test3\main.cpp|4|error: 'int d' previously declared here| C:\Programming\Test3\main.cpp|4|warning: unused variable 'c' [-Wunused-variable]| C:\Programming\Test3\main.cpp|4|warning: unused variable 'd' [-Wunused-variable]| C:\Programming\Test3\main.cpp|5|warning: unused variable 'a' [-Wunused-variable]| ||=== Build finished: 4 errors, 3 warnings (0 minutes, 2 seconds) ===| |
int b = 1, a = 2;
attempts to redeclare it, which is illegal. That's why I said the comma in this situation is an operator and not a separator. It operates the declaration of variables, or just expressions (it depends on if there is a data type to declare a variable).
|
|
|
|
|
|
cire wrote: |
---|
Since the former is illegal, I don't see how it could translate to the latter. Then again, I'm not sure what you're saying with the latter since it is also illegal syntax. |
If you knew that to be true, why did you try to do the same thing yourself and say it was legal? |
a = b, c, d ;
which I'd considered you actually might've had in mind for int a = (b, c, d);
because it made no sense.
That's why I said the comma in this situation is an operator and not a separator. It operates the declaration of variables |
cire wrote: |
---|
because it made no sense. |
helios wrote: |
---|
It's not an operator. An operator is something that does something with expressions and forms expressions. An expression is something that has a value and can be assigned to a variable. If the declaration comma is an operator, then what's the value of a declaration? Likewise for the parameter separator. |
int a = b, c, d;
is (a = b), (c), (d). Now, here is where the abstraction comes from. All of those can be assigned, they're considered rvalues. The assignment comes in the place of the data type, in this case, int. So, the comma operator separates then evaluates each section, then assigns it to the declaration of an int. So we get:
|
|
it separates, then evaluates |
The expression in int a = b, c, d; is (a = b), (c), (d). |
|
|
The expression in int a = b, c, d; is (a = b), (c), (d). Now, here is where the abstraction comes from. All of those can be assigned, they're considered rvalues. The assignment comes in the place of the data type, in this case, int. So, the comma operator separates then evaluates each section, then assigns it to the declaration of an int. What argument do you have against that logic (besides it just isn't an operator)? |
5.18.2 In contexts where comma is given a special meaning, [ Example: in lists of arguments to functions (5.2.2) and lists of initializers (8.5) —end example ] the comma operator as described in Clause 5 can appear only in parentheses.[ Example: f(a, (t=3, t+2), c); has three arguments, the second of which has the value 5. —end example ] |
int a = b++, c = b++, d=b++;
For instance, given the properties of the comma operator you might think that: int a = b++, c = b++, d=b++; was well defined, but it's not. |
Can you find a source on this? |
func(b++, b++, b++)
would be.cire wrote: |
---|
so evaluations of the init-declarators are unsequenced, |
8[dcl.decl]/3
The quoted portion clearly rules out the comma operator behavior here, so evaluations of the init-declarators are unsequenced, and thus the behavior is undefined as b is being modified more than once per 1.9.15, just the same as func(b++, b++, b++) would be. |
|
|
A full-expression is an expression that is not a subexpression of another expression. ... Every value computation and side effect associated with a full-expression is sequenced before every value computation and side effect associated with the next full-expression to be evaluated. |
Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself. |
cire wrote: |
---|
5.18.2 In contexts where comma is given a special meaning, [ Example: in lists of arguments to functions (5.2.2) and lists of initializers (8.5) —end example ] the comma operator as described in Clause 5 can appear only in parentheses.[ Example: f(a, (t=3, t+2), c); has three arguments, the second of which has the value 5. —end example ] |