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,905a7c70138a61ab X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-16 15:55:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3BCCBA9F.544FC58B@Raytheon.com> From: Mark Johnson X-Mailer: Mozilla 4.5 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Initialising stuff References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 16 Oct 2001 17:54:24 -0500 NNTP-Posting-Host: 192.27.48.44 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1003272956 192.27.48.44 (Tue, 16 Oct 2001 17:55:56 CDT) NNTP-Posting-Date: Tue, 16 Oct 2001 17:55:56 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:14759 Date: 2001-10-16T17:54:24-05:00 List-Id: "chris.danx" wrote: > Hi, > > I need a variable (global) for a screen package (write to video memory) and > would like it to be initialised once and once only when the package is > "with"ed. Not sure what you mean by "with"ed. If I with your package 5 times, do you want the global variable initialized 5 times? Somehow I don't think so. If you want it initialized just once, the "Ada word" you are looking for is elaboration. Basically, it is code that runs prior to "execution" to create and initialize all the variables that are declared in each package. It is a simple idea but in any complex system has a lot of issues to be addressed. > I can think of one way to do this... > > package body xxx is > ... > begin > initialise screen stuff here; > end xxx; > > but I'm unsure if this will work as I don't know the issues involved. Will > this work bearing in mind the purpose of the package? In general, yes. There are cases where a package does not require a body. If you use GNAT as the Ada compiler, it can warn you of that situation. Not sure on other vendor products. > Is the following the same or similar? > > package xxx is > > ... > > private > type yyy > is record > abc : byte := 0; > end record; > a_yyy : yyy; > end xxx; Other than the extra level of declarations - yes. You could just as easily say.... package xxx is type Byte is mod 256; yyy : Byte := 0; ... end xxx; and avoid the use of the record structure. If you use gnat as the compiler and gvd as the debugger, you can step through the elaboration code as it executes, set break points on variable initialization, and so on. Works really nice to find the problems in elaboration that you might not be able to find any other way. --Mark