comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Possible GNAT problem with aliased parameters.
Date: Sat, 19 Oct 2013 23:29:05 -0700 (PDT)
Date: 2013-10-19T23:29:05-07:00	[thread overview]
Message-ID: <2f2f46da-e6c2-4e0c-a5d2-3859975b67c9@googlegroups.com> (raw)
In-Reply-To: <28e86e6c-f2e1-4cca-abce-cd6f73447f4d@googlegroups.com>

On Saturday, October 19, 2013 3:17:17 PM UTC-6, Shark8 wrote:
> 
> 

My solution was to use renames on the parameters and then allocate new memory for the copies. It's not great, but there's no accessibility errors... I'm not sure if I ought to use Unchecked_Deallocate and/or Finalize here though. (Also, pools might be nice to ensure that things really do get cleaned up upon scope-exit.)

-- In the Spec:
------------------------------------
    Function Create (
		    Location_Name : String; -- Unique ID-string
		    North, South, East, West,
		    Up, Down : Story_Location'Class:= Nowhere
		    ) return Story_Location;

-- In the Body:
------------------------------------
    Function Create (
		    Location_Name : String;
		    North, South, East, West,
		    Up, Down : Maze'Class:= None
		    ) return Maze is
	
	N : Maze renames Maze(North);
	S : Maze renames Maze(South);
	E : Maze renames Maze(East);
	W : Maze renames Maze(West);
	U : Maze renames Maze(Up);
	D : Maze renames Maze(Down);
	
	Subtype Node is Maze( Length_N => Location_Name'Length );
    begin
	    Return Result : Node do
	    Result.Name := Location_Name;
	    Result.Exits:=
		(
		   Maze.North =>
		     (if N = Nowhere then null else New Maze'( N )),
		   Maze.South =>
		     (if S = Nowhere then null else New Maze'( S )),
		   Maze.East =>
		     (if E = Nowhere then null else New Maze'( E )),
		   Maze.West =>
		     (if W = Nowhere then null else New Maze'( W )),
		   Maze.Up => 
		     (if U = Nowhere then null else New Maze'( U )),
		   Maze.Down =>
		     (if D = Nowhere then null else New Maze'( D )),
		   others => null
		);
	End return;
    end;


  reply	other threads:[~2013-10-20  6:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-18 16:01 Possible GNAT problem with aliased parameters Shark8
2013-10-18 16:51 ` sbelmont700
2013-10-19  1:59   ` Randy Brukardt
2013-10-19  5:48     ` Shark8
2013-10-19  7:48       ` Dmitry A. Kazakov
2013-10-19 14:30       ` sbelmont700
2013-10-19 21:17         ` Shark8
2013-10-20  6:29           ` Shark8 [this message]
2013-10-20 15:33             ` sbelmont700
2013-10-21  0:29               ` Shark8
2013-10-21  0:55                 ` sbelmont700
replies disabled

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