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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: why "unconstrained subtype in component declaration" while said component given default value ? Date: Sun, 27 May 2018 09:45:48 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <2d717805-f6a4-4de9-bf4a-d45037034f96@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 27 May 2018 07:45:48 -0000 (UTC) Injection-Info: h2725194.stratoserver.net; posting-host="6346b21c01813e3ab3f80d4e7854f7f2"; logging-data="16633"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ippo6UWGJzf0Bm6xHlePft3Skfeg6liw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:eSxaRwGrXvsydmrImYy1gvVFxDs= In-Reply-To: <2d717805-f6a4-4de9-bf4a-d45037034f96@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:52718 Date: 2018-05-27T09:45:48+02:00 List-Id: On 05/26/2018 11:40 PM, Jere wrote: > > Consider for a second that you are the compiler and you need to > allocate a variable: > > My_Variable : A(10); > > What size (in bytes) do you need to allocate for the variable? Remember > that the function Give_String can be exceedingly complex or even a > function from a shared library. How do you at compile time determine > the size of that record type? There's more to it than that. Consider type R (L : Positive) is record S : String (1 .. L); end record; V : R (L => Some_Function); This is valid Ada, but the compiler cannot tell the size in bytes to allocate for V. However, the compiler can generate code to determine the size at run time. In its most basic form, this concept is type R is record S : String := Some_Function; end record; V : R; which is not much different from the valid declaration S : String := Some_Function; so it seems to me that the invalid form could be allowed. The latter declaration was invalid in Ada 83; on more than one occasion I wrote C : constant String := Some_Function; S : String (C'range) := C; to get around this restriction (and hoped the compiler would be smart enough to see that there were no other references to C, and not keep 2 copies of the value). -- Jeff Carter "Have you gone berserk? Can't you see that that man is a ni?" Blazing Saddles 38