[fpc-devel] bug: Inc(v,i)/Dec(v,i)
peter green
plugwash at bircd.org
Thu Jul 7 01:03:36 CEST 2005
shouldn't it implement inv(v,-1) in exactly the same way it implements
v:=v-1?
> -----Original Message-----
> From: fpc-devel-bounces at lists.freepascal.org
> [mailto:fpc-devel-bounces at lists.freepascal.org]On Behalf Of Marcel
> Martin
> Sent: 06 July 2005 23:36
> To: FPC developers' list
> Subject: Re: [fpc-devel] bug: Inc(v,i)/Dec(v,i)
>
>
> C Western a écrit :
> > Marco van de Voort wrote:
> >
> >>>>> var
> >>>>> v : cardinal;
> >>>>> begin
> >>>>> v:=100;
> >>>>> inc(v,-1);
> >>>>> end.
> >>>>>
> >>>>> The reason is that -1 is in fact an addition of $ffffffff resulting
> >>>>> in the
> >>>>> carry flag being set and therefor an overflow.
> >>>>
> >>>>
> >>>> For cardinal IMHO not-a-bug?
> >>>
> >>>
> >>> I think it's a bug for cardinals and other unsigned ints also (as
> >>> long as the
> >>> result is in the range of the result variable)
> >>
> >>
> >>
> >> -1 is not a valid cardinal -> out of range -> rangecheck error.
> >>
> > But on the other hand Dec(v,1) is fine, so Inc(v,-1) should also work.
>
> And if Dec(v,1) raises an overflow? Should Inc(v,-1) also do?
> If v = 0 (v is a longword), Dec(v,1) = overflow. So, Inc(v,-1),
> i.e., 0 + $ffffffff = overflow?
>
> I think Marco is right. Basically, when the compiler has to
> code Inc(x,SomeConstant), the only sensible behaviour it is
> expected to have is to regard the constant as being of the
> type of x. So, if x is a Longword and if SomeConstant equals
> -1, either it adds $ffffffff (and there will be an overflow
> if x > 0) or it stops at compile time saying that -1 is not
> a Longword.
>
> mm
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
More information about the fpc-devel
mailing list