comp.lang.ada
 help / color / mirror / Atom feed
* Unchecked Deallocation?
@ 2002-07-12 22:44 Caffeine Junky
  2002-07-12 23:12 ` Robert A Duff
  0 siblings, 1 reply; 6+ messages in thread
From: Caffeine Junky @ 2002-07-12 22:44 UTC (permalink / raw)


I think I'm getting a handle on using Unchecked Deallocation. However
I'm running into a problem. In my spec file I have these types defined...

with unchecked_deallocation;

generic
  type Item is private;

package genstack is 	-- A basic generic stack. Singlely linked list. --

        type stack is limited private;
        ...  -- Some other procedures defined here. --       
	function Clear_Stack(S : in Stack) return Boolean;


private

	type Cell;
	type stack is access Cell;
	type Cell is record
	   Value: Item;
	   Next: Stack;
	end record;

end genstack;


Now in the body of the package I have this...

package body genstack is

	procedure Free is new Unchecked_Deallocation(Cell, Stack);

	.....	-- Some other procedures here  --

	function Clear_Stack(S : in Stack) return Boolean is -- Return True or
													 -- or False if the
													 -- operation succeeded. --

	begin

	  Free(Stack);
	  return True;	   -- No reason for it not to return True in this --
				   -- instance, as far as I can tell.             --
        end Clear_Stack;

end genstack;

Now, when attempting to compile the code, I get this...

	41. Free(Stack)
	         |
        >>> Invalid use of subtype mark in expression or call
        >>> actual for 'X' must be a variable

I'm using Gnat 3.14p (Debian)


Now, as far as I can tell, I cannot give it an actual variable because
Cell is defined in the private type and is only accessible via the
'Stack' pointer variable. I dont think even Aliases can get past this
rule.
Also, the Unchecked_Deallocation documentation in the LRM that came with
GNAT (found it using GNU Info) shows Unchecked_Deallocation being
instantiated just the way I did it here.(Assuming I understood the docs.)
As does my "Programming in Ada95" book by John Barnes.
I suspect that it needs access to the Cell variable declared in the
private section, but I'm not sure how to do that safely.

Any pointers would be appreciated.

St4pL3



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

end of thread, other threads:[~2002-07-13  3:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-12 22:44 Unchecked Deallocation? Caffeine Junky
2002-07-12 23:12 ` Robert A Duff
2002-07-13  0:52   ` Caffeine Junky
2002-07-13  3:00     ` R. Tim Coslet
2002-07-13  2:31   ` tmoran
2002-07-13  3:10     ` Caffeine Junky

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