From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.176.1.16 with SMTP id 16mr18311419uak.8.1463341369158; Sun, 15 May 2016 12:42:49 -0700 (PDT) X-Received: by 10.157.52.5 with SMTP id v5mr193553otb.9.1463341369110; Sun, 15 May 2016 12:42:49 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!88no4468566qga.1!news-out.google.com!f14ni426ita.0!nntp.google.com!sq19no5944523igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 15 May 2016 12:42:48 -0700 (PDT) In-Reply-To: <2dc1c4a4-ec94-4cdf-95fc-c81f851c6845@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8202:8510:5985:2c17:9409:aa9c; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8202:8510:5985:2c17:9409:aa9c References: <5147eaaf-ca03-4288-8036-4f52c3364950@googlegroups.com> <2dc1c4a4-ec94-4cdf-95fc-c81f851c6845@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <68713bb9-e92e-469a-834e-9e7b82009e48@googlegroups.com> Subject: Re: Proof of array initialization in SPARK 2014 From: rieachus@comcast.net Injection-Date: Sun, 15 May 2016 19:42:49 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:30416 Date: 2016-05-15T12:42:48-07:00 List-Id: On Thursday, May 12, 2016 at 1:01:19 PM UTC+1, Dmitrij Novikov wrote: > I don't know how to cope with complex array initializations in SPARK. What is wrong with? function Initialize return My_Array is A : My_Array(1..8) :=3D (others =3D> True);=20 begin=20 A(A'Last) :=3D False;=20 return A; end Initialize; This code should be faster (if that matters), but has the advantage that A = is initialized before beginning the loop (that went away). You could also assign a constant array to A. You don't want A to be a cons= tant, so you do need an assignment. Or you could initialize to True, True,= True, True, True, True, True, False. But I assume that this example is a = simplified version of a more complex problem. Will the compiler generate a loop to initialize A, or build a constant into= the code? Depends on a lot of things, so what you get is what you get. ;-= ) In particular, if A fits in a register and is returned on the stack you = will probably get fast initialization. It is often worth defining a bit ar= ray type: subtype Index is Integer range 0 .. 31; type Bit_Array is array (Index range <>) of Boolean; Especially when working with hardware registers. (Change 31 to 15 for some= older hardware, and maybe 63 for some newest hardware.) It may seem that I worry more about speed than correctness, but in hard rea= l time (like radar) when you are bit twiddling registers inside interrupts,= you want code that eliminates non-stack memory references.