Re: [eigen] Indexes: why signed instead of unsigned? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Indexes: why signed instead of unsigned?
- From: Rui Maciel <rui.maciel@xxxxxxxxx>
- Date: Tue, 11 May 2010 15:40:09 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=Ru6QgKXsYInqyezJ3GFXMCk/xJ11nKHmRWofZBy0jNg=; b=DkNBm7kA86b3T5dfPLbiuksgzl5ripxjduoTh2seEIkS6ySWdth2F9NuEETACspgsZ 1Ah5W6Gbt1743jevqr+vL+N3/mwfARakwUtcrb8W91wBbMdLUOZrLNcV+FPLWMLMiKb5 pC1jqTkAgcTlnmB62MvrD6ni3CQL0Bh6RrflI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=S1O83Cyq4MZ4QUwspcxznLvhaYup5qpSjBJA1nahYGQMn62rKdGDN7lCMRDxY/gd9k MjsUSAyPF39vbnUUaXg04GxhAZCwG4J8XiSHBcRM1p64Pwron8hZRjUOtS1QchQJwlzM ISSv1FIs+IGFAleb83ammZ1eqN/BWq+FjKYjU=
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