comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@ada.eu.org>
To: gauthier@alphainfo.unilim.fr (Michel Gauthier)
Subject: Re: 'is-null' property through file keeping (to gurus)
Date: 1997/04/29
Date: 1997-04-29T00:00:00+00:00	[thread overview]
Message-ID: <m3pvvdn870.fsf@zaphod.enst.fr> (raw)
In-Reply-To: gauthier-2904971634240001@193.50.185.13



Michel> This is essentially a question to gurus.

This kind of sentence does not ensure an answer :-)

Michel> To avoid complex generic parameterising, I have made the
Michel> assumption that the property 'this pointer is null / not null'
Michel> is invariant when a pointer is written into then read from a
Michel> file. Another view of the same is 'the null pointer has only
Michel> one machine implementation and what is kept in a file is no
Michel> more than a fixed-sized bit sequence'. Can this be a
Michel> reasonable assumption ?

Well, you can turn it into a reasonable assumption if your compiler
follows the Implementation Advice given in 13.13 (7):

 "If a stream element is the same size as a storage element, then the
 normal in-memory representation should be used by Read and Write for
 scalar objects. Otherwise, Read and Write should use the smallest
 number of stream elements needed to represent all values in the base
 range of the scalar type"

Let me explain:

Pointers are not a scalar type, but you can define your own 'Read and
'Write attributes for the pointer types you define[1]. The 'Write
logic can then be:

  if pointer is null then write the boolean True to the stream
  otherwise write the boolean False then the pointer itself[2]

(the 'Read attribute is then straightforward)

If your compiler follows the implementation advice indicated above,
then it will ensure that in the case of a null pointer, you will have
a fixed size output since you will output a value of a scalar type in
the stream (True). Note that for a non-null pointer, it is still
undefined (furthermore, it is likely that it will be greater given
than one boolean and one pointer will be written to the stream).

Note that in practive, it is likely that your compiler use a fixed
size for a given access type, so all this discussion is probably
pointless.

To summarize, it is possible if you can find one particular value of
one particular type which gets written using a maximum number of bits
each time (you just write this particular value instead of a null
pointer and another one of the same type before a non-null pointer).

I'd be interested to know if this is possible to assume this without
this assumption.

  Sam

Footnotes: 
[1]  If you do not have the possibility to redefine attributes because 
     for example the pointer type is given as a generic formal, then
     you can create a new pointer type derived from the first one and
     redefine 'Read and 'Write for the new one. Then you use
     conversions between the two types when willing to write and read
     an element.

[2]  You will define yet another pointer type with standard Read and
     Write attributes for this one, to avoid calling your 'Write
     attribute recursively.
-- 
Samuel Tardieu -- sam@ada.eu.org




  reply	other threads:[~1997-04-29  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-29  0:00 'is-null' property through file keeping (to gurus) Michel Gauthier
1997-04-29  0:00 ` Samuel Tardieu [this message]
1997-04-29  0:00 ` Robert A Duff
replies disabled

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