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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,f0a123883ff0cb0f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.84.234 with SMTP id c10mr3124321wiz.4.1350352625244; Mon, 15 Oct 2012 18:57:05 -0700 (PDT) Path: q11ni134324915wiw.1!nntp.google.com!feeder2.cambriumusenet.nl!feeder1.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.12.MISMATCH!feed.xsnews.nl!border-2.ams.xsnews.nl!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: API design considerations - variable-length array in record type Date: Tue, 09 Oct 2012 08:42:08 +0300 Organization: Tidorum Ltd Message-ID: References: <86a6f9d1-c99f-4184-aa79-ab7c15af9d4c@googlegroups.com> Mime-Version: 1.0 X-Trace: individual.net tsVrfNO8zSLxl003eyQI0Qz9+liSIv9udnBpM+e2MGRcxZcRkG Cancel-Lock: sha1:H+g2asqqup7rWb6CGlRz7rXjT78= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: <86a6f9d1-c99f-4184-aa79-ab7c15af9d4c@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2012-10-09T08:42:08+03:00 List-Id: On 12-10-09 05:02 , Shark8 wrote: > On Monday, October 8, 2012 3:03:04 AM UTC-6, Maciej Sobczak wrote: >> >> type R is record >> X : Integer; >> Y : Unbounded_String; >> Z : Array_Of_Integers_That_We_Talk_About_Here; >> end record; >> >> Requirements: >> 1 - the enclosing record type should not be limited (it should be copyable) >> 2 - the record type can be explicitly controlled, if necessary >> 3 - the record type should be definite (it should not require initialization) >> 4 - it should be possible to assign to Z, just as it is possible to assign to X and Y, and the new value for Z *might have a different length* > > Why not use discriminants on the record? > > Default : Constant := Natural'First; > type R( Array_Length : Natural:= Natural'First ) is record > X : Integer; > Y : Unbounded_String; > Z : Array_Of_Integers_That_We_Talk_About_Here(1..Array_Length):= (Others => Default); > end record; Requirement 4 is not satisfied: if you assign a new value to R.Z, it has to have the same length as the old value (R.Array_Length). You can change the length only by assigning a new value, with the new discrimant value, to the whole record. And there is the memory usage problem that Adam described. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .