- Why does this compile?

From: CFB Software <"CFB>
Date: Wed, 10 Oct 2007 12:08:49 +0930

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

> -----Original Message-----
> From: blackbox{([at]})nowhere.xy
> Behalf Of Rex Couture
> Sent: Wednesday, 10 October 2007 12:44 AM
> To: BlackBox Mailing List
> Subject: [BlackBox] - Why does this compile?
>
>
> At 01:42 AM 10/9/2007, Bernhard Treutwein wrote:
> >it compiles for the same reason why the following
> >compiles:
> >
> >PROCEDURE Crash*;
> >VAR i: INTEGER; a: ARRAY 4 OF REAL;
> >BEGIN
> > i:= -800;
> > a[i]:= i
> >END Crash;
>
>
> Yes, thanks. It just came as a surprise that it does
> not even attempt to check array bounds at compile time.
>

> Rex Couture
>


I am not surprised that the compiler would find it difficult to check
array bounds when the index value is a *variable*.

However, I would have been surprised if the compiler did not check the
array bounds when the index value is a *constant* as it should be able
to evaluate the value of the constant at compile time. e.g.

PROCEDURE Crash*;
  CONST i: -800;
  VAR a: ARRAY 4 OF REAL;
BEGIN
  a[i]:= i
END Crash;

Fortunately, BlackBox *does* report this as an error at compile time.

If you need some more insight into what the compiler can be / can't be
expected to be able to do when checking array bounds, refer to Chapter
10.3 'Index Variables and Record Fields' of Niklaus Wirth's Compiler
Construction book. You can download a copy from:

http://www.oberon.ethz.ch/books.html

Regards,
Chris Burrows

CFB Software
http://www.cfbsoftware.com/gpcp


 

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


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

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZ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G8gQ2hhcHRlclxwYXINCjEwLjMgJ0luZGV4IFZhcmlhYmxlcyBhbmQgUmVjb3Jk
IEZpZWxkcycgb2YgTmlrbGF1cyBXaXJ0aCdzIENvbXBpbGVyXHBhcg0KQ29uc3RydWN0aW9uIGJv
b2suIFlvdSBjYW4gZG93bmxvYWQgYSBjb3B5IGZyb206XHBhcg0KXHBhcg0KaHR0cDovL3d3dy5v
YmVyb24uZXRoei5jaC9ib29rcy5odG1sXHBhcg0KXHBhcg0KUmVnYXJkcyxccGFyDQpDaHJpcyBC
dXJyb3dzXHBhcg0KXHBhcg0KQ0ZCIFNvZnR3YXJlXHBhcg0KaHR0cDovL3d3dy5jZmJzb2Z0d2Fy
ZS5jb20vZ3BjcFxwYXINClxwYXINClxwYXINCiBccGFyDQpccGFyDQotLS0gQmxhY2tCb3hccGFy
DQotLS0gc2VuZCBzdWJqZWN0IEhFTFAgb3IgVU5TVUJTQ1JJQkUgdG8gYmxhY2tib3hAb2Jlcm9u
LmNofX0AZXJvbi5jaABTTQ==


----boundary-LibPST-iamunique-621364277_-_---
Received on Wed Oct 10 2007 - 04:38:49 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:31:16 UTC