From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: The answer to "Can Ada replace FORTRAN for numerical computation?
Date: Fri, 16 Aug 2019 22:15:17 +0200
Date: 2019-08-16T22:15:17+02:00 [thread overview]
Message-ID: <qj72sn$gjn$1@dont-email.me> (raw)
In-Reply-To: <ZMCdnaTVUKdaYsvAnZ2dnUU7-TvNnZ2d@giganews.com>
On 8/16/19 9:11 PM, Norman Worth wrote:
>
> with ada.text_io; use ada.text_io;
> procedure ar is
> type a is array(integer range <>) of integer;
> type ap is access a;
> P : ap;
> procedure da (i : in integer; j : in integer; p : out ap) is
> begin
> p := new a(1..i);
> p.all := (others => j);
> end;
> begin
> da (4, 10, P);
> put_line (P(4)'image);
> da (10, 4, P);
> put_line (P(10)'image);
> end;
>
> (Note that since Ada does not have a "free" verb, memory management is a bit
> more complicated, requiring "uncontrolled deallocation", which is type
> sensitive, to explicitly deallocate the memory for each instance of P. But Ada
> will take care of deallocation nicely when P goes out of scope at the end of the
> procedure.)
Like 99.9% of all problems, we can do the same thing without writing "access" or
using Unchecked_Deallocation. Clearer and safer.
--
Jeff Carter
"Crucifixion's a doddle."
Monty Python's Life of Brian
82
next prev parent reply other threads:[~2019-08-16 20:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 4:38 The answer to "Can Ada replace FORTRAN for numerical computation? Nasser M. Abbasi
2019-07-22 5:53 ` Simon Wright
2019-07-22 10:32 ` Lucretia
2019-07-22 13:20 ` Simon Wright
2019-07-22 17:27 ` Lucretia
2019-07-24 23:45 ` Randy Brukardt
2019-08-15 16:45 ` Norman Worth
2019-08-15 19:07 ` Dmitry A. Kazakov
2019-08-16 18:29 ` Norman Worth
2019-08-16 19:23 ` Dmitry A. Kazakov
2019-08-18 17:04 ` Norman Worth
2019-07-23 1:35 ` Brad Moore
2019-07-23 23:42 ` Jerry
2019-08-03 12:30 ` Nasser M. Abbasi
2019-08-05 14:35 ` Shark8
2019-08-05 17:15 ` Optikos
2019-08-07 6:35 ` Niklas Holsti
2019-08-07 20:42 ` Optikos
2019-08-16 19:11 ` Norman Worth
2019-08-16 20:15 ` Jeffrey R. Carter [this message]
2019-08-17 2:38 ` robin.vowels
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox