comp.lang.ada
 help / color / mirror / Atom feed
From: progers@ajpo.sei.cmu.edu (Pat Rogers)
Subject: Re: Readonly variables in Ada?
Date: 5 Jun 90 13:21:22 GMT	[thread overview]
Message-ID: <677@ajpo.sei.cmu.edu> (raw)
In-Reply-To: 1990Jun5.085654.920@lth.se

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( <as before> ) 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

  reply	other threads:[~1990-06-05 13:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-06-05  8:56 Readonly variables in Ada? Christian S. Collberg
1990-06-05 13:21 ` Pat Rogers [this message]
1990-06-05 16:22 ` David Collard
1990-06-05 18:01 ` Robert I. Eachus
replies disabled

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