comp.lang.ada
 help / color / mirror / Atom feed
From: Wilhelm Spickermann <wilhelm.spickermann@t-online.de>
To: comp.lang.ada@ada.eu.org
Subject: RE: Simplest way to protect a variable ?
Date: Fri, 07 Sep 2001 15:15:45 +0200 (CEST)
Date: 2001-09-07T15:15:45+02:00	[thread overview]
Message-ID: <mailman.999868688.28873.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <9na3h6$1i6$1@snipp.uninett.no>


On 07-Sep-01 Reinert Korsnes wrote:
> Wilhelm Spickermann wrote:
> 
>> 
>> On 07-Sep-01 Reinert Korsnes wrote:
>>> Hi,
>>> 
>>> 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.
>>> 
>>> I may have several co-programmers I do not trust :-)
>>> 
>>> What is the simplest way to do this (in Ada) ?
>>> 
>> 
>> A : constant array ( ... ) of ... := file_reading_function (...);
>> 
>> Wilhelm
>> 
>> 
> 
> Yes, I got this idea but the file reading function reads mode than 
> a simple array.  I could collect the variables in a record maybe...

Another possibility is to put all these things into a package and use read-only
pointers ("access constant"). In the initialization of the package body
the file is read and all the variables (only one in the example code) are
filled:

package A_Package is
   pragma Elaborate_Body;
   type A_Type is array (1 .. 3) of Integer;
   type A_Read_Only_Access is access constant A_Type;
   Read_Only_A : constant A_Read_Only_Access;
private
   A : aliased A_Type;
   Read_Only_A : constant A_Read_Only_Access := A'ACCESS;
end A_Package;

package body A_Package is
begin
   --  read the file and fill Variable A
   ...
end A_Package;

Wilhelm




  parent reply	other threads:[~2001-09-07 13:15 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 [this message]
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
replies disabled

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