Re: [eigen] Indexes: why signed instead of unsigned?

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


On Mon, May 10, 2010 at 4:42 PM, Rui Maciel <rui.maciel@xxxxxxxxx> wrote:
>
> Benoit Jacob wrote:
>> See e.g. answer here:
>>
>> https://bitbucket.org/eigen/eigen/issue/106/index-and-size-type
>>
>> Benoit
>
>
> According to the example given in that answer, if we rely on a loop similar
> to:
>
> for(int col = cols() - 1; col>=0; --col)
>
>
> Does the cols() method deed to te signed?  To put it in other words,
> independently of what value int col will assume throughout the loop, isn't the
> output of cols() always positive?

The problem is the decrement. The variable col (if e.g. unsigned int)
will reach 0 and then it will be decremented resulting in an underflow
(and a huge positive value) and an endless loop. If we changed cols()
and returned an int we would always need to cast and theoretically
take care that cols() fits into an int.

- Hauke



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