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.2 required=5.0 tests=BAYES_05,GAPPY_SUBJECT, INVALID_DATE,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!ucivax!gateway From: jduarte@liege.ICS.UCI.EDU (J o s e D u a r t e) Newsgroups: comp.lang.ada Subject: Re: Types defining h/w r/o or w/o registers Message-ID: <9105311025.aa04299@PARIS.ICS.UCI.EDU> Date: 31 May 91 17:26:39 GMT Reply-To: Jose Aleman Duarte X-Newsgroups: comp.lang.ada X-Original-Path: ucivax!orion.oac.uci.edu!usc!cs.utexas.edu!titan!gardner X-References: <3949@titan.tsd.arlut.utexas.edu> In-Reply-To: <3949@titan.tsd.arlut.utexas.edu> X-Organization: UC Irvine Department of ICS List-Id: > Is there some way to define a type such that all variables of that > type can be only read or only written? For instance, I have a type that > defines the status register of some peripheral which can only be > read. It would be best if the compiler could flag any assignments > to variables of such a type as errors. > Is there some other means for commonly handling this problem? The > compiler being used is VADSWorks, if an implementation-defined solution > is required. Well...Ada is "the" language which explicitly allows you to name variables which can ONLY be read/written/read-write using the procedure syntax: with REGISTERS; use REGISTERS; procedure XYZ(Reg1: in REGISTER; Reg2: out REGISTER; Reg3: in out REGISTER) is begin -- Reg1 can only be used effectively as a constant in this scope -- Reg2 can only be assigned to in this scope -- Reg3 can be assigned to or read from in this scope null; end XYZ; . . . Alternatively, you can define a "type" and then define a constant variable of that type for read only variables... subtype XYZ is INTEGER; NY_REG: constant XYZ := 0; -- define a variable that can only be read . . . to define a type in a package that does not have ":=" implicitly defined...use a "limited private" syntax: package REGS is type XYZ is limited private; -- insert your procedures/functions here private type XYZ is NEW WHATEVER; end REGS; --- This would not allow other programmers that use your package to assign --- to a variable of type "XYZ" unless you also specified an "Assign" procedure. --- Look up "limited private" types for more details. I believe that "limited --- private" means that "=" (and thus "/=") and ":=" are not implicitly --- allowed for that type unless the package also explicitly defines --- "Assign" and "Read-From" procedures Jose' D.