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=-1.9 required=5.0 tests=BAYES_00,LOTS_OF_MONEY autolearn=ham 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 07:29:53 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dennison@telepath.com (Ted Dennison) Newsgroups: comp.lang.ada Subject: Re: Novice help with types and de-allocation. Date: 18 Nov 2002 07:29:53 -0800 Organization: http://groups.google.com/ Message-ID: <4519e058.0211180729.10b630dc@posting.google.com> References: NNTP-Posting-Host: 65.115.221.98 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1037633393 18046 127.0.0.1 (18 Nov 2002 15:29:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 18 Nov 2002 15:29:53 GMT Xref: archiver1.google.com comp.lang.ada:31046 Date: 2002-11-18T15:29:53+00:00 List-Id: Stapler wrote in message news:... > Alright, I have a package which more or less works but I'm having trouble > in a couple spots. I've placed comments where I'm having trouble. > type Buff_Out is array(Positive range <>) of Integer; ... > type Int_Buffer is array(1..Size) of Integer; ... > 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); 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. Probably the best way out would be to make Int_Buffer a *subtype* of Buff_Out, instead of a type in its own right. If you don't like that solution, then the next best thing would be to make the private definition of "Int_Buffer" a "new Buff_Out". That would allow you to use a simple type conversion. Do *not* used Unchecked_Conversion for this. Unchecked_Conversion is not for bailing yourself out of a badly-designed type system. Use it for when you truly have multiple different ways of looking at the data (eg: A complicated record that requires a CRC at the end, so it must also be an array of unsigned bytes).