Re: [eigen] odd behaviour of operator[]

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


2009/6/18 Andre Krause <post@xxxxxxxxxxxxxxxx>:
>        states[a, 0] = sin(0.1*a);
>        states[a, 1] = sin(0.2*a);
>        states[a, 2] = sin(0.3*a);
> oddly enough, this code compiles fine and executes without asserts, but assigns
> strange values to the array.

GCC gives a warning about the ',' operator having no effect. Due to
operator precedence and stuff, the comma is evaluated and then the
result of that comma is passed to the [] operator.

It is the equivalent of writing:  states[(a, 0)] = sin(0.1*a);
Which is the same as:  a; states[0] = sin(0.1*a);

See http://msdn.microsoft.com/en-us/library/zs06xbxh(VS.80).aspx



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/