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!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Why can't objects be static in Ada? Date: Thu, 11 Apr 2019 17:49:06 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Thu, 11 Apr 2019 22:49:06 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="1991"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader01.eternal-september.org comp.lang.ada:56116 Date: 2019-04-11T17:49:06-05:00 List-Id: "Lucretia" wrote in message news:b411a770-5e86-4d5e-9e43-e52843be724d@googlegroups.com... > Someone sent in a pull request to my bindings and had to change a few >constants to functions because objects can't be static. This is nonsense: Max : constant Integer := 10; is an object, and it's static. >For an example: > > type Sizes is > record > Width : Dimension; > Height : Dimension; > end record with > Convention => C; This is a composite type. Only numeric types and strings (and the latter is a hack) can be static. > Zero_Size : constant Sizes := (others => Natural_Dimension'First); > > Why can't Zero_Size be compiled as static in this pre-elaborated package? Because composite types are never static. A compiler that treated it as "static" would be wrong. OTOH, that doesn't prevent a compiler from evaluating it at compile-time. And the categorization pragmas are an area where the original scheme was a failure. The idea that the properties of every operation of a type can all have the same restrictions is maddening. Hopefully, the Global aspect will fix this. There's no good reason (outside of Annex E issues) for declaring any package preelaborated, unless you like fighting errors a lot. C.4 is a load of hooey, it's not actually implementable on the margins, and there's no reason for any compiler to generate more code than necessary. Ergo, you'll most likely get the same code whether or not you declare something Preelaborated, so why bother with all of the hassles? > This seems to be a major flaw in Ada imo. "Preelaborated packages" are a minor flaw of Ada, but you never have to use them. And if you don't, the rest of it is irrelevant. So I see no "major flaw". That said, I would have preferred allowing the declaration of user-defined static types, because it is annoying to write representation clauses as it stands. (Since X'Size is only static for numeric types, it's nearly useless in representation aspects. Which makes them more complex than necessary. But at worst, that is an annoyance.) It was deemed too complicated for too little benefit this time around. Feel free to bring it up again if you still care and don't mind waiting another 5+ years. Randy.