Re: Multiple assignment

2011-02-26 Thread spir
On 02/26/2011 01:56 AM, bearophile wrote: Is this program showing a bug in multiple assignments (DMD 2.052)? void main() { int i; int[2] x; i, x[i] = 1; assert(x == [1, 0]); // OK int j; int[2] y; y[j], j = 1; assert(y == [0, 0]); // Not OK } At the

Re: Multiple assignment

2011-02-26 Thread spir
On 02/26/2011 04:26 AM, Steven Schveighoffer wrote: Let me fix that for you: func(j++, y[j]) That should be illegal: a statement used as expression, but keeping it's effect anyway, and not the least kind of, namely an assignment, meaning a change of the program state. Denis --

Re: Multiple assignment

2011-02-26 Thread Jonathan M Davis
On Saturday 26 February 2011 00:51:45 spir wrote: On 02/26/2011 04:26 AM, Steven Schveighoffer wrote: Let me fix that for you: func(j++, y[j]) That should be illegal: a statement used as expression, but keeping it's effect anyway, and not the least kind of, namely an assignment,

Re: Multiple assignment

2011-02-26 Thread Dan Olson
Jonathan M Davis jmdavisp...@gmx.com writes: On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's undefined behavior in C and C++. It is not defined whether j's previous or

Re: Multiple assignment

2011-02-26 Thread Jonathan M Davis
On Saturday 26 February 2011 11:18:20 Dan Olson wrote: Jonathan M Davis jmdavisp...@gmx.com writes: On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's undefined

Multiple assignment

2011-02-25 Thread bearophile
Is this program showing a bug in multiple assignments (DMD 2.052)? void main() { int i; int[2] x; i, x[i] = 1; assert(x == [1, 0]); // OK int j; int[2] y; y[j], j = 1; assert(y == [0, 0]); // Not OK } At the end of the program I expect y to be [1,0] instead of

Re: Multiple assignment

2011-02-25 Thread simendsjo
On 26.02.2011 01:56, bearophile wrote: Is this program showing a bug in multiple assignments (DMD 2.052)? void main() { int i; int[2] x; i, x[i] = 1; assert(x == [1, 0]); // OK int j; int[2] y; y[j], j = 1; assert(y == [0, 0]); // Not OK } At the end

Re: Multiple assignment

2011-02-25 Thread Ali Çehreli
On 02/25/2011 04:56 PM, bearophile wrote: Is this program showing a bug in multiple assignments (DMD 2.052)? void main() { int i; int[2] x; i, x[i] = 1; I haven't heard about multiple assignments but that's the comma operator up there, separating (and sequencing) two

Re: Multiple assignment

2011-02-25 Thread bearophile
simendsjo: I couldn't find any info on the comma expression in the language reference, but this was my first google hit: A comma expression contains two operands of any type separated by a comma and has *left-to-right* associativity. The left operand is fully evaluated, possibly

Re: Multiple assignment

2011-02-25 Thread Ali Çehreli
On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's undefined behavior in C and C++. It is not defined whether j's previous or past value is used in y[j]. I would expect the situation be the same in D. Ali

Re: Multiple assignment

2011-02-25 Thread Jonathan M Davis
On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's undefined behavior in C and C++. It is not defined whether j's previous or past value is used in y[j]. I would expect the

Re: Multiple assignment

2011-02-25 Thread Steven Schveighoffer
On Fri, 25 Feb 2011 21:10:59 -0500, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's undefined behavior in C and C++. It is not

Re: Multiple assignment

2011-02-25 Thread Jonathan M Davis
On Friday, February 25, 2011 19:26:14 Steven Schveighoffer wrote: On Fri, 25 Feb 2011 21:10:59 -0500, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y;

Re: Multiple assignment

2011-02-25 Thread Ali Çehreli
On 02/25/2011 06:10 PM, Jonathan M Davis wrote: On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's undefined behavior in C and C++. It is not defined whether j's previous or

Re: Multiple assignment

2011-02-25 Thread Jonathan M Davis
On Friday 25 February 2011 22:32:47 Ali Çehreli wrote: On 02/25/2011 06:10 PM, Jonathan M Davis wrote: On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote: On 02/25/2011 05:09 PM, bearophile wrote: int j; int[2] y; y[j] = j = 1; I think that's