[fpc-pascal]Re: "for" loop questions
jonas at zeus.rug.ac.be
Sun Dec 8 11:49:24 CET 2002
On Sun, 8 Dec 2002 XHajT03 at mbox.vol.cz wrote:
> This isn't really correct either; this would only be true if you
> assign the result of subtraction to an unsigned variable; the
> calculation itself is done after conversion to a signed type.
This isn't entirelly correct. The decision about what the resulttype
of a calculation will be is decided in the following order (so once a
rule matches, that rule is used and the other rules aren't tried
1) one operand is an int64 -> result is int54
2) one operand is a qword -> result is qword
3) one operand is a cardinal and the other is also a cardinal or a
positive constant -> result is cardinal
4) one operand is cardinal and the other is a signed type or a negative
-> if range or overflow checking is on: convert everything to int64
-> if range and overflow checking is off: convert everything to cardinal
5) all other cases: convert everything to longint, result is longint
Note that the above is for 1.0.x of the compiler, I think 1.1 may have
been made a little more "intelligent", so that e.g. a byte + byte is
calculated using longint arithmetic, but that the result is still a byte.
So to get back to the original expression: cardinal - 1 = cardinal.
However, since someone else said the result of that count method is a
longint, the result will be a longint.
Finally, in response to the original poster: "for x := 0 to -1 do..." will
indeed not exexcute any iteration under FPC.
More information about the fpc-pascal