* array and pointers
@ 2003-11-22 9:39 shoko
2003-11-22 10:16 ` Gautier Write-only
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: shoko @ 2003-11-22 9:39 UTC (permalink / raw)
hi
i am new in ada
my question is:
i have a function that returns unconstrained array
i am tring to create a pointer to the new array
could somone help me:
what is wwrong in the following code?:
type Arr is Array(Item range<>) of Integer;
a:Arr:=(1,2,2,2,3,4,3) ;
type n_array_Ptr is access Arr;
n: n_array_Ptr;
begin
n:= new Array_filter(a);
put_line("hello");
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: array and pointers
2003-11-22 9:39 array and pointers shoko
@ 2003-11-22 10:16 ` Gautier Write-only
2003-11-22 15:16 ` Steve
2003-11-22 17:45 ` Jeffrey Carter
2 siblings, 0 replies; 5+ messages in thread
From: Gautier Write-only @ 2003-11-22 10:16 UTC (permalink / raw)
shoko:
# what is wwrong in the following code?:
#
# type Arr is Array(Item range<>) of Integer;
# a:Arr:=(1,2,2,2,3,4,3) ;
# type n_array_Ptr is access Arr;
# n: n_array_Ptr;
#
# begin
# n:= new Array_filter(a);
#
# put_line("hello");
A good idea is to read what the compiler says.
Here a test with GNAT:
arrrrrrr.adb:9:14: "Array_filter" is undefined
Okay, surely you meant "Arr" instead of "Array_filter".
n:= new Arr(a);
Let's try again:
arrrrrrr.adb:9:17: if qualified expression was meant, use apostrophe
arrrrrrr.adb:9:18: expect subtype mark for index constraint
If you want to copy a into the new n.all you have to use apostrophe
n:= new Arr'(a);
HTH
________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: array and pointers
2003-11-22 9:39 array and pointers shoko
2003-11-22 10:16 ` Gautier Write-only
@ 2003-11-22 15:16 ` Steve
2003-11-22 17:45 ` Jeffrey Carter
2 siblings, 0 replies; 5+ messages in thread
From: Steve @ 2003-11-22 15:16 UTC (permalink / raw)
To create a new dynamically allocated array and initialize it with the
result from Array_Filter use:
N := new Arr'( Array_Filter( A ) );
Also, since you say you're new to Ada, I'll also mention that this is an
unusual way of doing things in Ada. A more common approach is to use
something like:
declare
Filtered_Data : Arr := Array_Filter( A );
begin
-- Do stuff with Filtered_Data here
end;
Which avoids dynamic allocation on the heap altogether.
Steve
(The Duck)
"shoko" <shoko2004@hotmail.com> wrote in message
news:4948f537.0311220139.570c8a4e@posting.google.com...
> hi
> i am new in ada
> my question is:
> i have a function that returns unconstrained array
> i am tring to create a pointer to the new array
> could somone help me:
>
> what is wwrong in the following code?:
>
> type Arr is Array(Item range<>) of Integer;
> a:Arr:=(1,2,2,2,3,4,3) ;
> type n_array_Ptr is access Arr;
> n: n_array_Ptr;
>
> begin
> n:= new Array_filter(a);
>
> put_line("hello");
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: array and pointers
2003-11-22 9:39 array and pointers shoko
2003-11-22 10:16 ` Gautier Write-only
2003-11-22 15:16 ` Steve
@ 2003-11-22 17:45 ` Jeffrey Carter
2003-11-23 2:09 ` Hyman Rosen
2 siblings, 1 reply; 5+ messages in thread
From: Jeffrey Carter @ 2003-11-22 17:45 UTC (permalink / raw)
shoko wrote:
> i am new in ada
>
> i have a function that returns unconstrained array
> i am tring to create a pointer to the new array
Why? As an Ada beginner, you probably have no need for pointers at all,
unless you are creating a dynamically linked data structure. Pointers
are needed much more rarely in a high-level language such as Ada than
they are in low-level languages such as C and its derivatives.
--
Jeff Carter
"Why don't you bore a hole in yourself and let the sap run out?"
Horse Feathers
49
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: array and pointers
2003-11-22 17:45 ` Jeffrey Carter
@ 2003-11-23 2:09 ` Hyman Rosen
0 siblings, 0 replies; 5+ messages in thread
From: Hyman Rosen @ 2003-11-23 2:09 UTC (permalink / raw)
Jeffrey Carter wrote:
> Pointers are needed much more rarely in a high-level language such as Ada
> than they are in low-level languages such as C and its derivatives.
It happens that Ada lets you make arrays (and other things) with dynamic
sizes and C does not. I don't know that this is enough to qualify Ada as
being "high-level" and C not.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-11-23 2:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-22 9:39 array and pointers shoko
2003-11-22 10:16 ` Gautier Write-only
2003-11-22 15:16 ` Steve
2003-11-22 17:45 ` Jeffrey Carter
2003-11-23 2:09 ` Hyman Rosen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox