From: Colin Paul Gloster <Colin_Paul_Gloster@ACM.org>
Subject: Re: Novice help with types and de-allocation.
Date: Mon, 18 Nov 2002 11:05:13 +0000
Date: 2002-11-18T11:04:32+00:00 [thread overview]
Message-ID: <3DD8C969.D28416F8@ACM.org> (raw)
In-Reply-To: sX%B9.65239$NH2.4291@sccrnsc01
The thread starter had:
--snip
package int_buff is
type Int_Buffer is limited private;
--snip
type Buff_Out is array(Positive range <>) of Integer;
--snip
function Read_Buff( Y : in Int_Buffer; Read_length : in Natural;
Loc :in Natural) return Buff_Out;
--snip
private
--snip
type Int_Buffer is array(1..Size) of Integer;
--snip
end int_buff;
package body int_buff is
--snip
function Read_Buff(Y : in Int_Buffer; Read_Length : in Natural;
Loc : in Natural) return Buff_Out is
Ret_Buff : Buff_Out(1..Read_Length);
begin
-- For some reason, the compiler expects Y to be of type
Buff_Out.
-- Do I need to use Unchecked_Conversion here?
Ret_Buff := Y(Loc .. Read_Length - 1);
return Ret_Buff;
end Read_Buff;
--snip
end int_buff;
The compiler expects Y to be of type Buff_Out because you are assigning
a slice of Y (all or part of the array Y) to something which is of type
Buff_Out. Buff_Out is also an array of integers, but even if the slice
was the same size as the size of your Buff_Out array, this would be
illegal (arrays which just happen to have the same size in Ada of the
same component types are not the same array array types unless they were
actually declared to be of the same type).
Unchecked_Conversion can be nasty, so can this replacement line:
Ret_Buff := Buff_Out(Y(Loc .. Read_Length - 1));
which is also a conversion. Just make sure it is safe (e.g. that Y(Loc
.. Read_Length - 1) is not longer than Ret_Buff and that if it is
shorter than Ret_Buf, that you are happy with the unfilled in parts
being the way that they are).
next prev parent reply other threads:[~2002-11-18 11:05 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 [this message]
2002-11-18 15:29 ` Ted Dennison
2002-11-18 21:33 ` Stapler
2002-11-18 23:34 ` Stapler
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