dsimcha wrote:
 >> While ago, I got D multi-dimensional array syntax messed up and
 >> declared such an animal as
 >> int[3,4,5] which effectively ended up declaring the beast as int[5].
 >
 > The comma operator is another piece of C cruft that needs to go.
 >
 >> Cheers Justin

Can someone please explain to me what the comma operator does?  I've seen this
mentioned here before, but I really don't know.  Then again, if the only people
who use it are crufty old C language lawyers and people who have never 
programmed
seriously in C before don't know about it, I guess that's an indicator that it's
not worth much.

When (sub)expressions are separated with the comma operator, each (sub)expression is evaluated from left to right in turn (as if the individual (sub)expressions where separated by ; (semicolon) statement separator.
The result returned by the overall expression is the result returned
by the last (sub)expression (i.e., following the last comma).

In the array example above, int[3,4,5], the dimension expression 3,4,5
evaluates 3 (a constant), then 4 (another constant), and then 5 (yet another constant) and returns 5, this being the last subexpression
evaluated.  This is why the array ended up being effectively a
single dimension array of length 5.

Justin

Reply via email to