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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:6c50:: with SMTP id w77mr2518286itb.40.1554987376840; Thu, 11 Apr 2019 05:56:16 -0700 (PDT) X-Received: by 2002:a9d:6381:: with SMTP id w1mr9333217otk.314.1554987376433; Thu, 11 Apr 2019 05:56:16 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!136no140483itk.0!news-out.google.com!r82ni156ita.0!nntp.google.com!b2no139364itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 11 Apr 2019 05:56:16 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=185.34.132.4; posting-account=Srm5lQoAAAAEMX9rv2ilEKR6FDPapmSq NNTP-Posting-Host: 185.34.132.4 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <565a03a8-9194-4814-b21c-a5b61b8185b7@googlegroups.com> Subject: Re: Why can't objects be static in Ada? From: Mark Lorenzen Injection-Date: Thu, 11 Apr 2019 12:56:16 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:56114 Date: 2019-04-11T05:56:16-07:00 List-Id: On Thursday, April 11, 2019 at 2:40:40 PM UTC+2, Lucretia wrote: > Someone sent in a pull request to my bindings and had to change a few constants to functions because objects can't be static. For an example: > > type Sizes is > record > Width : Dimension; > Height : Dimension; > end record with > Convention => C; > > Zero_Size : constant Sizes := (others => Natural_Dimension'First); > > Why can't Zero_Size be compiled as static in this pre-elaborated package? > > This seems to be a major flaw in Ada imo. > > Luke. I don't think it's not an Ada flaw. From an Ada perspective the object is constant - irrespective if it's static (it's value is set at compile-time) or not. I guess it's compiler-dependent. There are a number of cases where GNAT could be better at generating static objects. This is especially true for objects of a (discriminated) record type. Try adding "Restrictions (No_Elaboration_Code)" to the spec and see if it forces GNAT into doing what you want to. Regards, Mark L