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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7c47766edd175974 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-02 08:01:45 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: How do package body initializers get run in GNU Ada? User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Sat, 2 Nov 2002 16:00:47 GMT Content-Type: text/plain; charset=us-ascii References: <3DC31EBB.2050809@math.jpl.nasa.gov> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:30308 Date: 2002-11-02T16:00:47+00:00 List-Id: Van Snyder writes: > In GNU Ada, what mechanism is used to cause execution of package > body initializers, i.e., the code between begin and end in a > package body? > > Is it done using some kind of back-patching/overlaying done > by an otherwise garden-variety ld, by special features added > to ld to support Ada, by first-time flags at the entries > to procedures, or by something else? I believe most Ada compilers do not use such features of the linker. Instead, they provide a program called the "builder" or "prelinker". The compiler generates a procedure for each compilation unit, containing the elaboration code. The builder constructs a "main" that calls all those elaboration procedures in a correct order, and then calls the user-defined main procedure. The builder normally then invokes the system linker (e.g. 'ld'), with all that code, telling it the automatically constructed "main" is the program's entry point (*not* the user-defined main procedure). Note that the elaboration code for a package body is not just the code between "begin" and "end". It also includes initialization code for all kinds of declarations. E.g., if you say "X: Integer := Func(...);", the elaboration code must call Func and initialize X to the result. Similarly, package specs also have elaboration code. - Bob