comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: How to do it in Ada ?
Date: Mon, 16 Jul 2001 05:31:21 GMT
Date: 2001-07-16T05:31:21+00:00	[thread overview]
Message-ID: <3B527C15.2B0E5BCC@acm.org> (raw)
In-Reply-To: 9itna2$i5b$1@news.tpi.pl

Tomasz Wegrzanowski wrote:
> 
> int main(int argc, char **argv)
> {
>     int *x;
>     int n;
> 
>     n = (argc==1)?1:atoi(argv[1]);
>     x = malloc (n*sizeof(int));
>     for (x=0;x<n;x++)
>         x[i]=0;
> 
>     /* ... */
> }
> 
> Something like that ... how to do such dynamic array allocation in Ada ?

The simple answer is, you don't. Ada makes this kind of thing much
simpler and less error-prone than in a low-level language.

procedure The_Right_Way is
   type List is array (Positive range <>) of Integer;

   function Get return Positive is separate;

   Num_Integers : constant Positive := Get;

   X : List (1 .. Num_Integers) := (others => 0);
begin -- The_Right_Way
   ...
end The_Right_Way;

Note that everything in your example is done in the declarative part.

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus



  reply	other threads:[~2001-07-16  5:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-16  3:33 How to do it in Ada ? Tomasz Wegrzanowski
2001-07-16  5:31 ` Jeffrey Carter [this message]
2001-07-16  6:41 ` Al Christians
2001-07-16  6:51 ` tmoran
2001-07-16 16:56   ` Mark Lundquist
2001-07-16 18:42     ` Nonsense (was Re: How to do it in Ada ?) Mark Lundquist
2001-07-16 22:20       ` Jeffrey Carter
2001-07-17  0:13       ` Ken Garlington
2001-07-17  3:53       ` Robert Dewar
2001-07-16 22:18     ` How to do it in Ada ? Jeffrey Carter
2001-07-17  4:06       ` tmoran
2001-07-20  5:39     ` David Thompson
2001-07-16 17:37   ` Ken Garlington
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox