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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,53e53000d1e9b814 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: [Q] : Unchecked conversion Date: 1996/11/12 Message-ID: <32888B01.1961@gsfc.nasa.gov>#1/1 X-Deja-AN: 196001710 references: <01bbce46$0f818680$829d6482@joy.ericsson.se> content-type: text/plain; charset=us-ascii organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA mime-version: 1.0 reply-to: Stephen.Leake@gsfc.nasa.gov newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; U) Date: 1996-11-12T00:00:00+00:00 List-Id: Jonas Nygren wrote: > > I have defined an IO buffer type which I intend to use for my own IO > packages. > The buffer type is defined as follows: > > subtype Byte is Integer range 0..255; > > type Buffer is array (Positive range <>) of Byte; > Pragma Pack(Buffer); > for Buffer'Component_Size use 8; > > [snip] > > function To_Buffer (S : String) return Buffer is > function Convert is > new Ada.Unchecked_Conversion(String, Buffer); > begin > return Convert(S); > end To_Buffer; > > but Gnat gives me an error: > > unconstrained type "Standard.String" not allowed in unchecked conversion > > [snip] As the error message implies, you need to constrain the types before instantiating Unchecked_Conversion: function To_Buffer (S : String) return Buffer is subtype Fixed_String is String (1 .. S'Length); subtype Fixed_Buffer is Buffer (1 .. S'Length); function Convert is new Unchecked_Conversion(Fixed_String, Fixed_Buffer); begin return Convert(S); end To_Buffer; I just tried this with Gnat, and it works. -- - Stephe