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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,73f097f1e2686cf5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-07 06:18:59 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!193.251.151.101!opentransit.net!jussieu.fr!enst!enst.fr!not-for-mail From: Wilhelm Spickermann Newsgroups: comp.lang.ada Subject: RE: Simplest way to protect a variable ? Date: Fri, 07 Sep 2001 15:15:45 +0200 (CEST) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit X-Trace: avanie.enst.fr 999868738 14610 137.194.161.2 (7 Sep 2001 13:18:58 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 7 Sep 2001 13:18:58 +0000 (UTC) To: comp.lang.ada@ada.eu.org Return-Path: X-Mailer: XFMail 1.4.0 on Linux X-Priority: 3 (Normal) In-Reply-To: <9na3h6$1i6$1@snipp.uninett.no> X-Sender: 0211750756-0001@t-dialin.net Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:12889 Date: 2001-09-07T15:15:45+02:00 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