comp.lang.ada
 help / color / mirror / Atom feed
From: Caffeine Junky <nospam@hotmail.com>
Subject: Unchecked Deallocation?
Date: Fri, 12 Jul 2002 22:44:10 GMT
Date: 2002-07-12T22:44:10+00:00	[thread overview]
Message-ID: <_YIX8.483917$352.79617@sccrnsc02> (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



             reply	other threads:[~2002-07-12 22:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-12 22:44 Caffeine Junky [this message]
2002-07-12 23:12 ` Unchecked Deallocation? 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
replies disabled

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