- BYTE arithmetic / overflows

From: CFB Software <"CFB>
Date: Fri, 23 Jun 2006 09:22:12 +0930

----boundary-LibPST-iamunique-2069834510_-_-
Content-type: text/plain

> -----Original Message-----
> From: blackbox{([at]})nowhere.xy
> Behalf Of H.v.L.
> Sent: Friday, 23 June 2006 2:05 AM
> To: BlackBox Mailing List
> Subject: [BlackBox] - BYTE arithmetic
>
>
> On Thu, 22 Jun 2006 17:10:33 +0200, Treutwein Bernhard
> <Bernhard.Treutwein{([at]})nowhere.xy
>
> >> The bottom line: use INTEGER as a loop counter. Do not use BYTE or
> >> SHORTINT.
> >>

> >
> > absolutely correct.
> >
>
> If this is to say that with type INTEGER the problems are
> gone I suggest trying the following loop
>
> FOR Index := MAX(INTEGER) - 10 TO MAX(INTEGER) DO
> Out.Int(Index, 15);
> IF (Index < 0) & (Index >= MIN(INTEGER) + 100) THEN RETURN
> END (* for convenience only *) END
>

FOR loops are recommended for specific tasks like iterating through arrays
so the examples discussed so far should not occur too often in practice.
Typically FOR loops look like this:

  FOR i := 0 TO ArraySize - 1 DO ...

However, anytime you are working with boundary conditions and there is a
potential for overflow you have to take the utmost care. It is not just a
FOR loop issue. If in doubt, compile with overflow checking enabled:

  DevCompiler.CompileOpt('+')

Regards,

Chris Burrows
CFB Software
http://www.cfbsoftware.com
  

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-2069834510_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b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CiAg
XHBhcg0KXHBhcg0KLS0tIEJsYWNrQm94XHBhcg0KLS0tIHNlbmQgc3ViamVjdCBIRUxQIG9yIFVO
U1VCU0NSSUJFIHRvIGJsYWNrYm94QG9iZXJvbi5jaH19AAAAEQAAANDdUgA=


----boundary-LibPST-iamunique-2069834510_-_---
Received on Fri Jun 23 2006 - 01:52:12 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:49 UTC