Marcel Martin wrote: > >>Unexpected overflows? The overflows occur or not according to > >>simple rules, perfectly defined, which ones depend on the types > >>of the operands. > > > > > > Unexpected as depending on the values, not on the types. When the ranges > > of the possible operands are known, it's also known whether an overflow > > can occur in computations with these operands. > > But overflows cannot be unexpected. If x is a Longword and > if x > 0, Inc(x,-1) will raise an overflow. And this is not > unexpected.
It is unexpected, for multiple reasons: 1) From online help in D4: >> Inc(X) corresponds to the statement X := X + 1, and Inc(X, N) corresponds to the statement X := X + N. << I cannot see any correspondence, when one form produces overflows, whereas the other form doesn't. 2) The overflow only occurs for special, machine specific conditions. The writer of high level language code IMO can expect that no machine specific details will influence the behaviour of his code, else the compiler at least must issue appropriate warnings. Since I don't have the current FPC compiler, I refer to D4 in this (hopefully) last example: type TCard = 0..1000; //or 0..$FFFFFFFF or 0..$8000 var x: TCard; const c = -1; begin x := 5; x := x + c; Inc(x, c); end; Here no overflow occurs, at least not in D4. An overflow occurs only in the special case where the upper bound of the type is $FFFFFFFF, in general when the highest bit in the highest byte of the memory representation is part of the type. Would you call this an expected behaviour? IMO the inconsistent behaviour of the above code is a bug. I can accept such behaviour only with respect to *full* Delphi compatibility, where every bug must be reproduced also by the FPC compiler. Otherwise I expect a consistent and machine independent compilation and execution of all high level language code. > We have a big, BIG, communication problem... I realized already that we are talking about different things :-( I'm talking about computation in general, you're talking about machine specific number representations and calculations. Please check your arguments with regards to unsigned types in general, i.e. any zero-based integer type. DoDi _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel