comp.lang.ada
 help / color / mirror / Atom feed
From: Ken Garlington <garlingtonke@lmtas.lmco.com>
Subject: Re: NVRAM or how can I enforce a range check in Ada83.
Date: 1996/11/16
Date: 1996-11-16T00:00:00+00:00	[thread overview]
Message-ID: <328DE73D.581B@lmtas.lmco.com> (raw)
In-Reply-To: 9611150709.AA09539@algol.ocag.ch


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 => <<byte array>>,
>                                                    Target => Elements);
>   begin
>      Item := Convert (<<Nvram_Byte_Array_Of_Element_Size>>);
>   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(<<Nvram_Byte_Array_Of_Element_Size>>);
>      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




  parent reply	other threads:[~1996-11-16  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-15  0:00 NVRAM or how can I enforce a range check in Ada83 Peter Vogelsanger
1996-11-15  0:00 ` Stephen Leake
1996-11-16  0:00 ` Ken Garlington [this message]
1996-11-17  0:00   ` Robert Dewar
1996-11-17  0:00     ` Robert A Duff
1996-11-18  0:00       ` Robert Dewar
1996-11-19  0:00         ` Robert A Duff
1996-11-22  0:00     ` Ken Garlington
1996-11-22  0:00       ` Robert Dewar
1996-11-25  0:00         ` Ken Garlington
1996-11-19  0:00   ` Laurent Guerby
replies disabled

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