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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4576669b9167cd1d X-Google-Attributes: gid103376,public From: Ken Garlington Subject: Re: NVRAM or how can I enforce a range check in Ada83. Date: 1996/11/16 Message-ID: <328DE73D.581B@lmtas.lmco.com>#1/1 X-Deja-AN: 196934537 references: <9611150709.AA09539@algol.ocag.ch> content-type: text/plain; charset=us-ascii organization: Lockheed Martin Tactical Aircraft Systems mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.02 (Macintosh; I; 68K) Date: 1996-11-16T00:00:00+00:00 List-Id: Peter Vogelsanger wrote: > > Hello Ada people (or fans ;-)) > > We are useing a Non Volatile RAM (EEPROM) in our project. The NVRAM driver > accesses the hardware by word operations. Now we've programmed a generic driver > which transform the generic type to a byte or word array. Because of the > possibility of an hardware error, we have to check the read values from the > NVRAM. We use an unchecked_conversion to transform from byte array to the > generic type. We have got no informations about the type inside this generic > procedure. > > Code: > > generic > type Elements is private; > procedure Read (Item : out Elements); > > procedure Read (Item : out Elements) is > function Convert is new Unchecked_Conversion (Source => <>, > Target => Elements); > begin > Item := Convert (<>); > end Read; > > The Unchecked_Conversion does not make any checks, therefore the name unchecked. > We've tried to use a temporary variable to assigne the unchecked_converion > value and then assigne our parameter with this temporary variable and hoped > that a check would be performed. > > begin > Temp := Convert(<>); > Item := Temp; > exception > when constraint_error => > << some critical action>> > end Read; > > But as I've read later the Reference Manual, I've seen that no range check are > done by an assignment. > > Now is there a construct that enforce the compiler to make a range check? But > remember in this generic procedure we haven't got any type information. > Also important: we use Ada83. Since the type you're passing in might be a composite type, there's no way realistically for the compiler to enforce a "range check", since such types don't really have such a thing (although their components might). There is an Ada 83 interpretation that says compilers are permitted to warn you if the Source and Target are of different sizes on an unchecked conversion, but as I understand it this isn't a requirement. (By the way, how do you know how big to make your byte/word array?) Best answer, as far as I can tell, is the user-written Validate procedure suggested previously. > > Has somebody any idea about this problem? > > Best Regards > > Peter > > -- LMTAS - "Our Brand Means Quality" For more info, see http://www.lmtas.com or http://www.lmco.com