comp.lang.ada
 help / color / mirror / Atom feed
* Controlled type question
@ 1999-02-14  0:00 Chad R. Meiners
  1999-02-15  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 3+ messages in thread
From: Chad R. Meiners @ 1999-02-14  0:00 UTC (permalink / raw)


I am constructing a generic hash table ADT with the gnat 3.11p compiler on win NT 4.0 SP3 and I have run into a 
compilier error when I try to use the generic package.

On this line in my main program

Package Hash_table is new Hash_table_Interfaces(My_Data,  --data type stored
						aword,    --data type of key to be hashed
						"=",	  --function for my_data
						"=",      --Function for the key
						Key,      --Function to get the key from My_data
						My_Hash); --Function to hash the key

I get the following errors
instantiation error at protected_hash_tables.ads :99
instantiation error at protected_hash_tables.ads :20
Controlled type must be declared at the library level

The lines in protected_hash_tables are

99 :  Type cObject is new Limited_Controlled with record
	Controler : Passive_Controller;  --Protected type;
	Copier    : Background_Controller_ptr;  --access to a task that 		
						--enlarges the hash table in the background
      end record;

20 :  Type cObject is new Limited_Controller with private;  --hash table object


the package compilied correctly so I think I might of run up against a rule in the ARM.  If anyone could explain 
what I did wrong please do so.  I will post more code if you need it.

-Chad R. Meiners





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

* Re: Controlled type question
  1999-02-14  0:00 Controlled type question Chad R. Meiners
@ 1999-02-15  0:00 ` Matthew Heaney
  1999-02-15  0:00   ` Chad R. Meiners
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 1999-02-15  0:00 UTC (permalink / raw)



v025@truman.edu (Chad R. Meiners) writes:

> I am constructing a generic hash table ADT with the gnat 3.11p
> compiler on win NT 4.0 SP3 and I have run into a compilier error when
> I try to use the generic package.

[snip]
 
> I get the following errors
> instantiation error at protected_hash_tables.ads :99
> instantiation error at protected_hash_tables.ads :20
> Controlled type must be declared at the library level
> 
> The lines in protected_hash_tables are
> 
> 99 :  Type cObject is new Limited_Controlled with record
...
> 20 :  Type cObject is new Limited_Controller with private;--hash table object
> 
> 
> the package compilied correctly so I think I might of run up against a
> rule in the ARM.  If anyone could explain what I did wrong please do
> so.  I will post more code if you need it.


Yes, you hit upon a rule, the one that says 

  Controlled type must be declared at the library level

You have this:

  package GP is
    ...
  private
    type T is new <controlled type> ...;
  end GP;


That's fine, but the illegal thing is doing this:

package Q is
...
   package P is new GP (...);

end Q;

The problem is that inside the scope of package Q, you're not at library
level, and so the instantiation of GP is illegal.

You can try fixing it like this:

package Q is
...
end Q;

private package Q.P is new GP (...);


(I think that's it.  Let me know if I interpreted things incorrectly.)




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

* Re: Controlled type question
  1999-02-15  0:00 ` Matthew Heaney
@ 1999-02-15  0:00   ` Chad R. Meiners
  0 siblings, 0 replies; 3+ messages in thread
From: Chad R. Meiners @ 1999-02-15  0:00 UTC (permalink / raw)


In article <m3zp6g1cs7.fsf@mheaney.ni.net>, matthew_heaney@acm.org says...
>
>
>Yes, you hit upon a rule, the one that says 
>
>  Controlled type must be declared at the library level
>
>You have this:
>
>  package GP is
>    ...
>  private
>    type T is new <controlled type> ...;
>  end GP;
>
>
>That's fine, but the illegal thing is doing this:
>
>package Q is
>...
>   package P is new GP (...);
>
>end Q;
>
>The problem is that inside the scope of package Q, you're not at library
>level, and so the instantiation of GP is illegal.
>
>You can try fixing it like this:
>
>package Q is
>...
>end Q;
>
>private package Q.P is new GP (...);
>
>
>(I think that's it.  Let me know if I interpreted things incorrectly.)

Thank you.  I wrote a four line ads file to do this and it works great.

-Chad R. Meiners





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

end of thread, other threads:[~1999-02-15  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-14  0:00 Controlled type question Chad R. Meiners
1999-02-15  0:00 ` Matthew Heaney
1999-02-15  0:00   ` Chad R. Meiners

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