comp.lang.ada
 help / color / mirror / Atom feed
From: Stapler <spam.magnet@yahoo.com>
Subject: Re: Novice help with types and de-allocation.
Date: Mon, 18 Nov 2002 23:34:50 GMT
Date: 2002-11-18T23:34:50+00:00	[thread overview]
Message-ID: <uOeC9.79060$1O2.4816@sccrnsc04> (raw)
In-Reply-To: 4519e058.0211180729.10b630dc@posting.google.com

On Mon, 18 Nov 2002 10:29:53 -0500, Ted Dennison wrote:

 
> The "some reason" is that the object you are assigning Y into is of that
> type. Unlike some other languages, in Ada you can't assign objects of
> one type into objects of a another type, just because both types have
> similar contents. You defined Int_Buffer and Buff_Out to be different
> types, so they are truly considered unrelated types.


Now that I reflect on it, it only makes sense. With a type declaration
like I was trying to use, what's to stop me from attempting to read past
the end of the Buffer array? If this was C, it would have been all hunky dory,
but the Ada compiler wouldn't even let it past the compile stage.

Now, I dont suppose that after entering my Read funtion I could do
something like the following ...

assuming I've did this in the spec...
subtype Return_Buffer is Buffer;

function Read( Y : in Buffer; Loc, Length : in Natural ) return
Return_Buffer is

	Check : Natural
begin

	Check := Loc + Length;
	if Loc > Buffer'Last then
		raise Exception;
	else if Length > Buffer'range then
		raise Exception;
	else if Check > Buffer'Last then
		raise Exception;
	else
		declare
			subtype Return_Buffer is Buffer(1..Length)
		begin

			-- process data here --

			return Return_Buffer;
		end;
	end if;
end Read;


Now, I'm hoping that this deals with the underyling issue of this
particular type declaration. However I'm still not sure if the compiler
would let that fly. (Gonna try compiling it when I get home from work.)

I suppose another option would be to create specific set of Input
procedures that would check to make sure that the values are always
within the range of the Buffer type.

I've been humbled by GNAT. What's a psuedo-developer to do? Heh.

Stapler



  parent reply	other threads:[~2002-11-18 23:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-18  6:40 Novice help with types and de-allocation Stapler
2002-11-18 11:05 ` Colin Paul Gloster
2002-11-18 15:29 ` Ted Dennison
2002-11-18 21:33   ` Stapler
2002-11-18 23:34   ` Stapler [this message]
2002-11-18 19:06 ` Jeffrey Carter
replies disabled

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