12/07/02 15:34:10, Steven Lim <[log in to unmask]> wrote:

>I'm wondering how do we declare a variable and NOT have it being
>initialized to zero?
>
>I'm mapping this variable to a non-volatile memory and hence
>would like to retain it's data.
>...

Hi Steve,

This is probably not the correct way to use non-volatile memory
(NVRAM). It may be that you know this and are simply taking a
short-cut (in which case apologies), but my preference in these
situations is to treat each piece of special memory as secondary
storage. The simplest way to do this in Ada 95 is to implement
the memory as a stream or a (stream) file.

(1) Define a record type T, with an exact representation clause,
which contains all the variables to be retained. At appropriate
times, use T'Write to write out these values to NVRAM. At
appropriate times, use T'Read to read them in again; use T'Valid
as well as semantic checks to ensure the values read are valid
(if they are not, use a default set of values instead). In
addition to the use of T'Valid, you could add a component to T
which contains a 'magic' value.

OR (2) [more complicated] For each type T of each variable to be
retained, use T'Write to write it out and T'Read to read it back
in again (and T'Valid to check it). The variables must all be
written together, and read back together (in the exact reverse
order!).

OR (3) [less compact but most flexible] Ditto as for (2) but use
Ada.Text_IO to read and write values (as text) instead. This
option can be a curly way to aid debugging.

The reason for this elaborate approach is to isolate the
locations and representations of data inside the program from
those as stored in NVRAM. This way, stored data may be re-usable
even if the program is modified (changing the location or
representation chosen for a retained variable). If the data in
NVRAM gets mucked up for any reason, this fact will (hopefully)
be detected, and sensible default values used instead.

Personally, I have always found the extra effort to use special
memory this way has always turned out to be worthwhile in the
end.

The way NVRAM is implemented as a stream or file is a bit
implementation-dependent. By the use of the Volatile pragma (RM95
C.6), it may be possible to overlay a Stream_Element_Array onto
it. [The word 'Volatile' is a bit ironic in this context ;-) ]
However it is done, it should be potted (into a separate
package).

Finally, I suppose I should point out that the Usenet newsgroup
comp.lang.ada is the usual venue for technical Ada questions.

Good luck,

--
Nick Roberts