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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!pt.cs.cmu.edu!sei!ajpo!progers From: progers@ajpo.sei.cmu.edu (Pat Rogers) Newsgroups: comp.lang.ada Subject: Re: Readonly variables in Ada? Summary: readonly variables Message-ID: <677@ajpo.sei.cmu.edu> Date: 5 Jun 90 13:21:22 GMT References: <1990Jun5.085654.920@lth.se> List-Id: In article <1990Jun5.085654.920@lth.se>, collberg@dna.lth.se (Christian S. Collberg) writes: > Is it possible to declare (the equivalent of) an exported readonly > variable in Ada? The best way I know is to use a discriminated record that is exported as a private/limited type. The discriminates are visible and thus readable, but since the type is actually private (or limited), they cannot be written to from outside the package's exported subprograms. You may also have internal variables (components of the exported record type) that cannot be seen at all, if you choose, or simply make the record empty via "null". For example: (This hasn't "experienced the joys of compilation" as a friend of mine says, but I have done it before, so to speak, and this is the general approach.) package Hardware is type Register( B0,B1,B2,B3,B4,B5,B6,B7 : Integer := 0 ) is private; procedure Set( R : in out Register; ...... ); -- other procedures and functions which operate on registers private type Register( ) is record null; -- or internal, hidden components end record; end Hardware; with Hardware; package Machine is Status : Hardware.Register; ... end Machine; >From here, Machine.Status.B0 etc can be read, but not written, since the type is private. Is that close to what you need? Regards, P Rogers Software Arts and Sciences