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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6bf481efd29cf77b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-11 14:56:46 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Behavior of Stream Attributes On Access Types. Date: Tue, 11 Jun 2002 16:56:25 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <4519e058.0206110547.526d2369@posting.google.com> X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:25767 Date: 2002-06-11T16:56:25-05:00 List-Id: Ted Dennison wrote in message <4519e058.0206110547.526d2369@posting.google.com>... >"Marin David Condic" wrote in message news:... >> My inclination is to think that the sensible thing would be to call the >> 'Read or 'Write for the thing pointed to by the access type, but this has > >You can pretty much count on it *not* doing that. For instance, what >would happen in that case with a circularly-referenced structure like >a doubly-linked list? > > >> implications for dynamically allocated objects. Will it write/read a >> (totally useless) access value? > >Pretty much. It isn't *totally* useless. It will work just fine within >the same execution (assuming you don't deallocate the memory). >However, it is next to useless. There is one more thing you can do with it: test it for nullness. Although that is not guarenteed to work, it would be an unusual system indeed where it did not. This can be very useful. The Janus/Ada compiler uses this to store and reconstruct linked lists: (Note that Janus/Ada, as an Ada 83 app., doesn't use the stream attributes themselves but a very similar implementation specific package) type Data; type Ptr is access Data; type Data is record ... Next : Ptr; end record; List : Ptr; procedure Write_List (To : Stream_Access) is Walk : Ptr := List; begin Ptr'Write (To, Walk); while Walk /= null loop Data'Write (To, Walk.all); Walk := Walk.Next; end loop; end Write_List; procedure Read_List (From : Stream_Access) is Work : Ptr; begin Ptr'Read (From, Work); if Work /= null then List := new Data; Work := List; else List := null; return; -- Nothing to read. end if; loop Data'Read (From, Work.all); if Work.Next = null then return; else Work.Next := new Data; Work := Work.Next; end; end loop; end Read_List; (There's probably a simpler way to read the list, but you get the idea...) Randy.