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: Mon, 7 Mar 2016 17:08:55 -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> <56dc7e22$0$19749$426a34cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Tue, 8 Mar 2016 00:05:53 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="48b46be33beed75863f69afa437f956b"; logging-data="9050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/njsoA6+vKRp4/v/EGHU4L/pypdV4I9bs=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: Cancel-Lock: sha1:ZaXu5OgO3jcEYoz5BpAa8mKS7Mw= Xref: news.eternal-september.org comp.lang.ada:29699 Date: 2016-03-07T17:08:55-07:00 List-Id: On 03/07/2016 04:16 PM, Randy Brukardt wrote: > "Xavier Petit" wrote in message > news:56dc7e22$0$19749$426a34cc@news.free.fr... > > I don't know if this is relevant... > >> procedure Test_Bounded_String is >> package Bounded_String is >> type T (Max_Length : Natural := 100) is limited private; > > ...but a type like this can be completed with a non-limited type. That might > prevent the compiler from applying a limited-only optimization. (Another way > to say it is that this type is not inherently limited; non-limited views can > exist of such types, and a non-limited view would need an allocate-the-max > strategy [or a non-contiguous object].) The compiler knows the full type (which is limited) when it compiles the variable declaration and its associated elaboration code. Would it not be able to use that information? > You might try making this type tagged, as that would make it inherently > limited and *might* allow the compiler to make the optimization. (Or it > simply might not work for any private type - optimizations are just that, > and it isn't always easy to apply them to partial views.) Otherwise, you'll > have to forgo using a private type (ugh, I know). My first reaction was that one can't have default discriminants for a tagged type. I see Ada-12 removed the rule against tagged types having default discriminants, prohibiting them only for non-limited tagged types. I try not to write code for languages with only a single compiler provider, so I still tend to adhere to the earlier rule. You can also remove the default and add a subtype with the discriminant specified. type Base_T (Max_Length : Natural) is [limited] private; -- limited no longer needed subtype T is Base_T (Max_Length => 100); though that's somewhat less convenient. -- Jeff Carter "I was hobbling along, minding my own business, all of a sudden, up he comes, cures me! One minute I'm a leper with a trade, next minute my livelihood's gone! Not so much as a 'by your leave!' You're cured, mate. Bloody do-gooder!" Monty Python's Life of Brian 76