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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: How much storage requires this record? Date: Tue, 19 Aug 2014 14:14:51 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1408472084 31287 192.74.137.71 (19 Aug 2014 18:14:44 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 19 Aug 2014 18:14:44 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:JvwOn7scvANm3uveCRdRN821QNQ= Xref: news.eternal-september.org comp.lang.ada:21836 Date: 2014-08-19T14:14:51-04:00 List-Id: Victor Porton writes: > How much storage requires the following record? I am afraid that in some > compilers each string would require about Natural'Last bytes (way too much). No, there are no Ada compilers that do that. The discriminants do not have defaults, which means every object of type Filename_And_Fragment is constrained, so they can't change size, so the compiler can (and will) allocate just the necessary amount. This size is calculated when the object is created (or at compile time, if possible). But if you add a default value: type Filename_And_Fragment (Filename_Length, Fragment_Length: Natural := 0) is then some objects can be unconstrained, and some compilers will allocate the max size for those. GNAT does that, and also warns about things like the above. Other compilers use a deallocate/reallocate strategy. Tying "all objects constrained" to "discrims do not have defaults" was a questionable design decision. It confuses programmers. To add to the confusion, if you add "limited" to the above, then you're back in the "can't change size" situation. > type Filename_And_Fragment (Filename_Length, Fragment_Length: Natural) is > record > Filename: String(1..Filename_Length); > Fragment: String(1..Fragment_Length); > end record; > > If the above is wrong (from memory positions), what is the right way to do > it? Nothing wrong with the above. - Bob