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

[ Thread Index | Date Index | More Archives ]

On 10 May 2010 15:55, Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx> wrote:
> On Mon, May 10, 2010 at 4:42 PM, Rui Maciel <rui.maciel@xxxxxxxxx> wrote:
>> 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.

That isn't in question.  The col variable can still remain unsigned
without any consequence on the rest of the code and the loop limit
given by the col() method will always be positive.

> If we changed cols()
> and returned an int we would always need to cast and theoretically
> take care that cols() fits into an int.

That's the question.  If the cols() method will only return
non-negative values then it is expected that it returns an unsigned
integer.  Moreover, data types such as size_t were designed and are
used for sizes of objects.  So, if the STL's containers also use
unsigned types with an equivalent purpose to methods such as the
cols() method, it would be a great help, at least conceptually, if the
components offered an interface that matches the standard interfaces.

Rui Maciel

Mail converted by MHonArc 2.6.19+