Wrong code gen / missing warning / my mistake?
Benjamin Thaut
code at benjamin-thaut.de
Mon Sep 10 12:32:45 PDT 2012
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
More information about the Digitalmars-d
mailing list