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 16:32:25 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.algonet.se!algonet!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail From: "chris.danx" Newsgroups: comp.lang.ada References: <3BCCBA9F.544FC58B@Raytheon.com> Subject: Re: Initialising stuff MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Wed, 17 Oct 2001 00:27:27 +0100 NNTP-Posting-Host: 62.253.10.71 X-Complaints-To: abuse@ntlworld.com X-Trace: news6-win.server.ntlworld.com 1003274832 62.253.10.71 (Wed, 17 Oct 2001 00:27:12 BST) NNTP-Posting-Date: Wed, 17 Oct 2001 00:27:12 BST Organization: ntlworld News Service Xref: archiver1.google.com comp.lang.ada:14763 Date: 2001-10-17T00:27:27+01:00 List-Id: "Mark Johnson" wrote in message news:3BCCBA9F.544FC58B@Raytheon.com... > "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. You are correct, only once. > 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. Now I get the "elaboration" idea, thanks. I'd read about it but couldn't quite get my head around the idea (part of the confusion was that i'd seen a pragma preelaborate in a similar package by Serge Robyns, and not knowing what it really meant I didn't use it. The difference between that package and my own is that I use a screen_info record to hold the position and current global attribute and initialise them inside the begin while Serges' package uses two natural subtypes in the body (and initialises them upon declaration). I can do that too, it's a lot simpler and nicer. > > 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; That was just an example, sorry (forgot the ... in the record, sorry). > 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. I'll try to remember that in future, it's good advice. Thanks, Chris