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: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Bounded String question Date: Wed, 11 Nov 2015 10:36:06 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <7ba56b33-28d4-42d2-8b9b-5ad9f5beab8b@googlegroups.com> <87io597447.fsf@theworld.com> <87egfw7dnm.fsf@theworld.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 11 Nov 2015 17:33:50 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="caa759af2a9c666aec02942f6fe5abd6"; logging-data="15946"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9JmtJQpHY59yNNY6PCxzlxkaVQHQnVks=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <87egfw7dnm.fsf@theworld.com> X-Mozilla-News-Host: news://freenews.netfront.net Cancel-Lock: sha1:bt59laFM9ZgwrCAOss5c1csZxlg= Xref: news.eternal-september.org comp.lang.ada:28305 Date: 2015-11-11T10:36:06-07:00 List-Id: On 11/11/2015 08:34 AM, Bob Duff wrote: > "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. I missed the "limited" and concentrated on the default for the discriminant. It does mean that assignment becomes a bit messy, though. -- Jeff Carter "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!" Robert Dewar 62