comp.lang.ada
 help / color / mirror / Atom feed
From: "chris.danx" <chris.danx@ntlworld.com>
Subject: Re: Initialising stuff
Date: Wed, 17 Oct 2001 00:27:27 +0100
Date: 2001-10-17T00:27:27+01:00	[thread overview]
Message-ID: <kn3z7.5367$nT1.923795@news6-win.server.ntlworld.com> (raw)
In-Reply-To: 3BCCBA9F.544FC58B@Raytheon.com


"Mark Johnson" <Mark_H_Johnson@Raytheon.com> 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




      reply	other threads:[~2001-10-16 23:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-16 20:16 Initialising stuff chris.danx
2001-10-16 20:40 ` Ted Dennison
2001-10-16 21:26   ` chris.danx
2001-10-17  2:42     ` Jeffrey Carter
2001-10-18  8:18       ` chris.danx
2001-10-16 22:54 ` Mark Johnson
2001-10-16 23:27   ` chris.danx [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox