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.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!software.org!collard From: collard@software.org (David Collard) Newsgroups: comp.lang.ada Subject: Re: implicit array type conversion Message-ID: <1469@software.software.org> Date: 26 Jul 90 20:36:49 GMT References: <1990Jul26.132742.3828@planck.uucp> Sender: news@software.org Reply-To: collard@software.org (David Collard) Distribution: na Organization: Software Productivity Consortium, Herndon, Virginia List-Id: In article <1990Jul26.132742.3828@planck.uucp> acsu.buffalo.edu!planck!hercules!westley () writes: > Why is it that implicit array type conversion does not apply to the > following situation? I can't find anything in the RM that disallows > this situation for implicit conversion. > > procedure Strings is > > type STRING (Len : NATURAL) is > record > S : Standard.STRING(1..Len); > end record; > > A : Standard.STRING(7..7); > B : STRING(1); ^^^^^^^^^^^^^^ At this point B is constrained to Len = 1. Which is why a constraint error is raised later. > > begin -- Strings > > A := "X"; > B := (A'length, A); > > end Strings; > An aggregate assignment which overrides the discriminant of a record is only allowed if the discriminant has a default and the object is not constrained when it is declared, i.e type STRING(Len : Natural := 0) is record S : Standard.STRING(1..Len); end record; B : String; If you change your declaration to this, then the assignment will not raise a constraint error. HOWEVER it still will not work because when the discriminant does have a default and an object is declared using the default , then the compiler will try to allocate enough space for the maximum value for the discriminant (probably over 2 billion if Natural is 32 bits) which is 1) Too much memory 2) Is beyond the maximum length for a string on some machines. What will work is: type String_Index is range 0..100; type String(Len : String_Index := 0) is record S : Standard.String(1..Natural(Len)); end record; B : String; But note that if the range of String_Index is large, you may be using a lot more memory than is apparent. The discriminated record is not intended to support dynamic allocation of different sized objects. If you really want dynamic allocation then use an access type. Good Luck -- ----------------------------------------------------------------------- D. Thor Collard Internet: collard@software.org Software Productivity Consortium UUNET: ...!uunet!software!collard 2214 Rock Hill Rd, Herndon VA 22070