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,3a20fa0a5423463c X-Google-Attributes: gid103376,public From: Samuel Tardieu Subject: Re: 'is-null' property through file keeping (to gurus) Date: 1997/04/29 Message-ID: #1/1 X-Deja-AN: 238181909 Sender: sam@zaphod.enst.fr References: To: gauthier@alphainfo.unilim.fr (Michel Gauthier) Organization: Sam's machine Newsgroups: comp.lang.ada Date: 1997-04-29T00:00:00+00:00 List-Id: 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