comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Johnson <Mark_H_Johnson@Raytheon.com>
Subject: Re: Initialising stuff
Date: Tue, 16 Oct 2001 17:54:24 -0500
Date: 2001-10-16T17:54:24-05:00	[thread overview]
Message-ID: <3BCCBA9F.544FC58B@Raytheon.com> (raw)
In-Reply-To: EA0z7.4255$nT1.766306@news6-win.server.ntlworld.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.

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




  parent reply	other threads:[~2001-10-16 22:54 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 [this message]
2001-10-16 23:27   ` chris.danx
replies disabled

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