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 w77mr4928434itb.40.1555160831770; Sat, 13 Apr 2019 06:07:11 -0700 (PDT) X-Received: by 2002:aca:4c08:: with SMTP id z8mr7648431oia.30.1555160831476; Sat, 13 Apr 2019 06:07:11 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.166.216.MISMATCH!136no220226itk.0!news-out.google.com!w17ni283itb.0!nntp.google.com!b2no221253itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 13 Apr 2019 06:07:11 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <842b24b2-4b9f-46ae-a173-87b70aac2959@googlegroups.com> Subject: Re: Why can't objects be static in Ada? From: Jere Injection-Date: Sat, 13 Apr 2019 13:07:11 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:56128 Date: 2019-04-13T06:07:11-07:00 List-Id: On Thursday, April 11, 2019 at 8:40:40 AM UTC-4, 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. Out of curiosity, are you looking for something more akin to C++'s constexpr [1][2] keyword? Ada's static definition is kind of like that, but not as flexible or usable yet. I'm hoping that at some point Ada does adjust the definition of static to be even more useful. Most compiler's do make things that are static potentially compile time, but I (think) I share your frustration in how limited the definition actually covers, especially in places where it would be obvious for the compiler to make that decision (well assuming the language definition would allow it). I think Ada202x is looking at improving the breadth of situations for static functions (maybe someone more versed can confirm this either way). This is definitely one of the few outliers in my embedded code as I work to move my old C++ embedded code into Ada designs. It's really frustrating to take such large hits on either performance (when dealing with small embedded boards) or better reusable design. Granted it is just a few outliers and I can find workarounds, but the workarounds occasionally can be more error prone and much more difficult to maintain. [1]: https://www.geeksforgeeks.org/understanding-constexper-specifier-in-c/ [2]: https://en.cppreference.com/w/cpp/language/constexpr