comp.lang.ada
 help / color / mirror / Atom feed
* how  to declare an array of pointers
@ 2003-11-01 16:18 lolo27
  2003-11-01 18:10 ` tmoran
  0 siblings, 1 reply; 5+ messages in thread
From: lolo27 @ 2003-11-01 16:18 UTC (permalink / raw)


i wrote the following code:
type node is
   record 
      emp_data:emp;
      next:p_node;
      prev:p_node;
   end record;   
   
   type ptr_array is
   record
      next:p_node; 
   end record;        
   type Array_Hash_type is array (10..HASH_SIZE) of ptr_array; 
   type Array_Hash_type_access is access Array_Hash_type;  
   Hash_Array : Array_Hash_type_access;


my question is:
is  Array_Hash_type  an array of pointers if not then how can i define one
i need an example

thank



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how  to declare an array of pointers
  2003-11-01 16:18 how to declare an array of pointers lolo27
@ 2003-11-01 18:10 ` tmoran
  2003-11-01 22:44   ` lolo27
  0 siblings, 1 reply; 5+ messages in thread
From: tmoran @ 2003-11-01 18:10 UTC (permalink / raw)


>my question is:
>is  Array_Hash_type  an array of pointers
  WYSIWYG.
>  type Array_Hash_type is array (10..HASH_SIZE) of ptr_array;

So Array_Hash_type is an array of "ptr_array"s.  Since
>  type ptr_array is
>  record
     ...
a ptr_array is a record, not a pointer.  So Array_Hash_type is
an array of records (which may contain pointers, etc).

>if not then how can i define one i need an example
   Assuming that "p_node" (which you didn't define in your posting)
is an access type (aka pointer), then
   type Array_Hash_type is array (10..HASH_SIZE) of p_node;
would be an array of pointers.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how  to declare an array of pointers
  2003-11-01 18:10 ` tmoran
@ 2003-11-01 22:44   ` lolo27
  2003-11-01 23:30     ` Jeffrey Carter
  0 siblings, 1 reply; 5+ messages in thread
From: lolo27 @ 2003-11-01 22:44 UTC (permalink / raw)


tmoran@acm.org wrote in message news:<GGSob.59310$275.144816@attbi_s53>...
> >my question is:
> >is  Array_Hash_type  an array of pointers
>  WYSIWYG.
> >  type Array_Hash_type is array (10..HASH_SIZE) of ptr_array;
> 
> So Array_Hash_type is an array of "ptr_array"s.  Since
> >  type ptr_array is
> >  record
>      ...
> a ptr_array is a record, not a pointer.  So Array_Hash_type is
> an array of records (which may contain pointers, etc).
> 
> >if not then how can i define one i need an example
>    Assuming that "p_node" (which you didn't define in your posting)
> is an access type (aka pointer), then
>    type Array_Hash_type is array (10..HASH_SIZE) of p_node;
> would be an array of pointers.

thanks now i have to change all my program
i dont understand how do i access an elemnt?

Array_Hash_type(index).something

 
i know i have to allocate each elemnt but how can i access elment 
with an index after he is allocated.

can you post me example?
where can i find example on the net? 
thanks a lot



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how  to declare an array of pointers
  2003-11-01 22:44   ` lolo27
@ 2003-11-01 23:30     ` Jeffrey Carter
  2003-11-02  0:04       ` tmoran
  0 siblings, 1 reply; 5+ messages in thread
From: Jeffrey Carter @ 2003-11-01 23:30 UTC (permalink / raw)


lolo27 wrote:

> i dont understand how do i access an elemnt?
> 
> Array_Hash_type(index).something
> 
> i know i have to allocate each elemnt but how can i access elment 
> with an index after he is allocated.
> 
> can you post me example?
> where can i find example on the net? 
> thanks a lot

It's apparent that you haven't developed a very good understanding of 
Ada yet, so I have to ask why you think you need pointers. Pointers are 
needed in Ada much less often than in many other languages. About the 
only time a beginner really needs pointers is to implement dynamic data 
structures, but such structures don't generally need arrays. It appears 
you may be trying to create a hash table, but I think you need to sit 
down with one of the fine on-line texts or tutorials and get to know the 
language a little better before you dive into something like that. A 
good place to look on the net for Ada resources is www.adapower.com; 
www.adaworld.com is another.

-- 
Jeff Carter
"Many times we're given rhymes that are quite unsingable."
Monty Python and the Holy Grail
57




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how  to declare an array of pointers
  2003-11-01 23:30     ` Jeffrey Carter
@ 2003-11-02  0:04       ` tmoran
  0 siblings, 0 replies; 5+ messages in thread
From: tmoran @ 2003-11-02  0:04 UTC (permalink / raw)


>>    type Array_Hash_type is array (10..HASH_SIZE) of p_node;
>i dont understand how do i access an elemnt?
>
>Array_Hash_type(index).something

If you have a particular array, say
     Main_Hash : Array_Hash_type;
then
     Main_Hash(i).all   is whatever whatever that particular p_node
points to.  In common cases you can skip the ".all", eg, if

   type Data is record
     Is_First_Name : Boolean;
     Name : String(1 .. 5);
   end record;

   type P_Node is access Data;

then

  Main_Hash(i).Is_First_Name is the boolean in the Data record at p_node, and
  Main_Hash(i).Name(1)  is the first character in the string at p_node,
and so forth.

>thanks now i have to change all my program
  Surely you didn't "code first, ask questions later"! ;)

>where can i find example on the net?
  In addition to the ones noted, you might do a search at
www.adaic.com/site/wide-search.html
In particular, look for things in the online Style and Quality guide.
  Also as noted, there are often better ways than using pointers to
accomplish things in Ada.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-11-02  0:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-01 16:18 how to declare an array of pointers lolo27
2003-11-01 18:10 ` tmoran
2003-11-01 22:44   ` lolo27
2003-11-01 23:30     ` Jeffrey Carter
2003-11-02  0:04       ` tmoran

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