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!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: Bounded String question Date: Wed, 11 Nov 2015 10:34:53 -0500 Organization: A noiseless patient Spider Message-ID: <87egfw7dnm.fsf@theworld.com> References: <7ba56b33-28d4-42d2-8b9b-5ad9f5beab8b@googlegroups.com> <87io597447.fsf@theworld.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b95a1959649799dee38fd87fab0df4e4"; logging-data="16534"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lc+qM+S/DQp8vUcxx23Oj" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:e7Feo+ols5j8ZrW7WkZJsNiCHtE= sha1:OW/cCTRbQ5uQdUrrv7FaZNnGrT0= Xref: news.eternal-september.org comp.lang.ada:28301 Date: 2015-11-11T10:34:53-05:00 List-Id: "Jeffrey R. Carter" writes: > On 11/10/2015 05:48 PM, Bob Duff wrote: >> >> I suggest rolling your own. No need for generics. >> >> type Bounded_String (Max_Length : Natural := ...) is limited record >> Length : Natural := 0; >> Chars : String (1 .. Max_Length); >> end record; > > Except that using Natural for Max_Length results in GNAT allocating Integer'Last > characters for Chars, which is unlikely to fit on the stack. No, the type is limited, so GNAT will allocate space for Max_Length characters, not Natural'Last characters. - Bob