From: dweller@dfw.net (David Weller)
Subject: Re: C++'s pointer vs Ada's Access type
Date: 1996/08/01
Date: 1996-08-01T00:00:00+00:00 [thread overview]
Message-ID: <4tqn1a$gb8@dfw.dfw.net> (raw)
In-Reply-To: 31FFD4A6.41C6@afit.af.mil
In article <31FFD4A6.41C6@afit.af.mil>,
Ding-yuan Sheu <dsheu@afit.af.mil> wrote:
>
>However, there comes a problem.
>In C++, ip can be a pointer that points to a integer array.
>Therefore, C++ programmers can do the following initialization:
>
> int Array[100];
> ip = &Array;
> for (i:=0;i++,99) { (*ip+i) = 0; }
>
>My question is how I can do the same thing in Ada by using ip
>to initialize Array instead to directly initialize Array.
>
There are a lot of "implicit" types in C++, but not in Ada. To
accomplish the code segment you have above, you must declare a type
that is an unconstrained array of integers:
type Int_Array is array(Natural range <>) of Integer;
-- I use Natural as the index to conceptually match C's arrays
Then you simply make a declaration:
A : Int_Array(0..99) := (others=>0);
No pointer arithmetic involved :-) (Although Ada does support it with
System.Storage_Elements package)
Did I answer the question, or misunderstand it?
--
Visit the Ada 95 Booch Components Homepage: www.ocsystems.com/booch
This is not your father's Ada -- lglwww.epfl.ch/Ada
prev parent reply other threads:[~1996-08-01 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-07-31 0:00 C++'s pointer vs Ada's Access type Ding-yuan Sheu
1996-08-01 0:00 ` johndoe
1996-08-01 0:00 ` Mark A Biggar
1996-08-01 0:00 ` Fraser Wilson
1996-08-01 0:00 ` Bryce Bardin
1996-08-01 0:00 ` David Weller [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox