Am 10.09.2012 19:58, schrieb Rainer Schuetze:
On 10.09.2012 19:08, Benjamin Thaut wrote:
 > The following code
 >
 >
 > bool endsWith(string str, string end)
 > {
 >      size_t to = str.length - end.length;
 >      for(sizediff_t i = str.length - 1; i >= to; --i)

Unfortunately, unsigned takes precedence over signed in any calculation,
so "i >= to" is an unsigned comparison, where i is converted to unsigned
first.

A lot of calculation that involve size_t and implicite conversions or
substractions are pretty error-prone.

If they are that error prone, shouldn't there be some kind of compiler warning?

Kind Regards
Benjamin Thaut

Reply via email to