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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c319c681003d3e4c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-17 16:59:27 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swiss.ans.net!solaris.cc.vt.edu!news.duke.edu!zombie.ncsc.mil!MathWorks.Com!noc.near.net!inmet!dsd!stt From: stt@dsd.camb.inmet.com (Tucker Taft) Subject: Re: Static in 9X Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: <940914130023_73672.2025_DHR31-2@compuserve.com> Date: Fri, 16 Sep 1994 10:26:48 GMT Date: 1994-09-16T10:26:48+00:00 List-Id: By the way, in private conversation it became clear that the real goal was more link-time initialization of large data structures. Although staticness is only defined for scalars and certain string expressions, there is no reason an implementation should not be *much* more aggressive in performing link-time initialization of data structures. RM9X does talk about preelaborability, which is closer to what is appropriate for link-time initialization, but even preelaborability is too conservative in many cases (and a bit too liberal in others). The goal of every Ada implementation should be that if there is no calculation that *needs* to be performed at run-time to initialize a data structure, then the data structure should be link-time initialized. Of course no implementation can really fulfill this goal -- it is probably equivalent to solving the halting problem -- but this should be the goal. The user can help out by avoiding things like: 1) anything that depends heavily on the run-time system (such as uses of allocators, anything tasking-related, etc.) and hence might involve building up linked lists, etc. 2) references to other variables or large constants in the aggregate initializing a large constant you hope will be link-time initialized. Just because something is link-time initialized, *don't* presume the compiler can perform indexing or selection into it at compile-time, because that implies keeping all of the data in memory, rather than just dumping it into the object module. For example: X : constant Blah := (1, 5, 8, 7, "abcde", 3.5, ...); Y : constant Boffo := (4, 7, X.F, 9, X.G, 2.7, ...); Expecting X to be link-time initialized is reasonable. Expecting Y to be is not, given the references to X inside it. 3) Any calls on user-defined functions, even if their bodies are "trivial" or inlined. Probably some compilers can handle even things like the above. In particular, there is a recommendation that allocators for access-to-constant types be handled at link-time, and I hope most Ada 9X compilers will do so. This should enable tables of pointers to error messages (or equivalent) to be link-time initialized. For example: type Error_Message is access constant String; Error_Table : array(Positive range <>) of Error_Message := (new String'("Naughty, naughty"), new String'("No way, Jose'"), new String'("You have got to be kidding"), ... ); The above should be link-time initializable. For those familiar with C and how string literals are represented (by a pointer into link-time allocated storage), the above should be treated as approximately equivalent to: char *error_table[] = { "Naughty, naughty", "No way, Jose'", "You have got to be kidding", ... }; It is not exactly the same because in Ada, strings have array bounds rather than a null terminator, but that shouldn't interfere with link-time initialization of a data structure like the above. Note that access-to-variable allocators can't be easily handled with link-time allocation, because unchecked-deallocation is allowed for access-to-variable types (it is not allowed for access-to-constant types in 9X). S. Tucker Taft stt@inmet.com Ada 9X Mapping/Revision Team Intermetrics, Inc. Cambridge, MA 02138