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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3a2f76c3562b7f58 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!b33g2000yqc.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: type String_Type array(Integer range <>) of Character; Date: Fri, 16 Apr 2010 13:56:03 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2dab1630-4abd-4d5b-a286-6fdbd18ce19c@b33g2000yqc.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1271451363 5818 127.0.0.1 (16 Apr 2010 20:56:03 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 16 Apr 2010 20:56:03 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b33g2000yqc.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:10030 Date: 2010-04-16T13:56:03-07:00 List-Id: On Apr 16, 1:29=A0pm, "J-P. Rosen" wrote: > stefan-lu...@see-the.signature a =E9crit :> Convert S into a variable of = type String_Type with String-compatible > > bounds, and then convert that variable into a String: > > > =A0 =A0 S : String_Type :=3D "Abc."; > > =A0 =A0 T : String_Type(1 .. S'Length) :=3D S; > > =A0 =A0 U : String(1 .. S'Length); > > =A0 begin > > =A0 =A0 =A0U :=3D String(T); Put_Line(U); =A0-- or just Put_Line(String= (T)); > > No need for intermediate copy, just use an appropriate subtype: > > =A0 =A0S : String_Type :=3D "Abc."; > =A0 =A0T : String(1..4); > =A0 =A0subtype Slide is String_type (T'Range); > begin > =A0 =A0T :=3D String(Slide(S)); You don't even need two type conversions: S : String_Type :=3D "Abc."; subtype String_Subtype is String(1..S'Length); T : String_Subtype; -- T : String(1..4); -- this works too begin T :=3D String_Subtype(S); Sometimes reading the manual helps (especially if you know where to look). 4.6(37-38) says about array type conversions: * If the target subtype is a constrained array subtype, then a check is made that the length of each dimension of the value of the operand equals the length of the corresponding dimension of the target subtype. The bounds of the result are those of the target subtype. * If the target subtype is an unconstrained array subtype, then the bounds of the result are obtained by converting each bound of the value of the operand to the corresponding index type of the target type. For each nonnull index range, a check is made that the bounds of the range belong to the corresponding index subtype. So if we're converting to a constrained subtype (like String_Subtype), it just makes sure the length is the same on each dimension; while if we're converting to an unconstrained subtype (like String), then each bound is expected to be the same. So we solve the problem by making the type conversion target a constrained subtype. -- Adam