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: Peter Vogelsanger Subject: NVRAM or how can I enforce a range check in Ada83. Date: 1996/11/15 Message-ID: <9611150709.AA09539@algol.ocag.ch>#1/1 X-Deja-AN: 196819814 sender: Ada programming language x-sun-charset: US-ASCII comments: cc: czvop@hydra.ocag.ch newsgroups: comp.lang.ada Date: 1996-11-15T00:00:00+00:00 List-Id: 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. Has somebody any idea about this problem? Best Regards Peter >