Wrong code gen / missing warning / my mistake?

Rainer Schuetze r.sagitario at gmx.de
Mon Sep 10 10:58:11 PDT 2012


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.


More information about the Digitalmars-d mailing list