comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison<dennison@telepath.com>
Subject: Re: Simplest way to protect a variable ?
Date: Fri, 07 Sep 2001 13:21:51 GMT
Date: 2001-09-07T13:21:51+00:00	[thread overview]
Message-ID: <PR3m7.7884$4z.32894@www.newsranger.com> (raw)
In-Reply-To: 9n9r4c$srt$1@snipp.uninett.no

In article <9n9r4c$srt$1@snipp.uninett.no>, Reinert Korsnes says...
>Let's say I initiate a "global" variable, A (for example an array), by
>calling a procedure (which may read data from a file).  And I want to be
>sure that the content (value) of this variable is not changed by
>another procedure.  The variable is "global" in the sense that it is 
>available in many many other routines.   

If I take the literal interpretation of what you are saying, you want one
routine to be able to set it once, and everyone else only having read-only
access.

The easiest way to do that is to declare it as a constant in its package spec.
If you need a function to initialize it, put the function in a package that
doesn't depend on your package's body, and do a pramga elaborate_all on its
package when you "with" it.

A more flexible way to do it is to put the global variable inside the package
body of the setter. For all the read-only clients, provide a function in the
package spec that returns the current value of the variable. Code in the package
body can now muck with your global at will, but no-one else can (unless you
provide them a routine to do so). Among other benifits, this allows you to
change the implementation of your "global" without affecting your read-only
clients.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



      parent reply	other threads:[~2001-09-07 13:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-07  6:50 Simplest way to protect a variable ? Reinert Korsnes
2001-09-07  8:21 ` Peter Amey
2001-09-07  8:45 ` Wilhelm Spickermann
2001-09-07  9:13   ` Reinert Korsnes
2001-09-07  9:16     ` Reinert Korsnes
2001-09-07 13:15     ` Wilhelm Spickermann
2001-09-07 11:35   ` Reinert Korsnes
2001-09-07 13:26     ` Ted Dennison
2001-09-09 18:03       ` martin.m.dowie
2001-09-07 13:03 ` DuckE
2001-09-07 13:21 ` Ted Dennison [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