From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e02dc5f2c4718ab X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-18 03:04:32 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.esat.net!feeder.news.heanet.ie!193.1.198.47.MISMATCH!not-for-mail Message-ID: <3DD8C969.D28416F8@ACM.org> Date: Mon, 18 Nov 2002 11:05:13 +0000 From: Colin Paul Gloster Reply-To: Colin_Paul_Gloster@ACM.org X-Mailer: Mozilla 4.74 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Novice help with types and de-allocation. References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Organization: Dublin City University (DCU) Cache-Post-Path: ns2-ext.dcu.ie!unknown@136.206.10.108 X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) NNTP-Posting-Date: 18 Nov 2002 11:04:32 GMT NNTP-Posting-Host: 136.206.1.1 X-Trace: 1037617472 reader.news.heanet.ie 180 [::ffff:136.206.1.1]:36618 Xref: archiver1.google.com comp.lang.ada:31034 Date: 2002-11-18T11:04:32+00:00 List-Id: 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).