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,fa2221f5dd5f5100 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-24 18:57:22 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <816517EFDE1ABFFF.672EFD9C99861B55.1999743ACE4BA64B@lp.airnews.net> Subject: Re: Newbie question about pointers in GNAT 3.15p on Windows 2000 : to Steve X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc02 1046141841 12.211.13.75 (Tue, 25 Feb 2003 02:57:21 GMT) NNTP-Posting-Date: Tue, 25 Feb 2003 02:57:21 GMT Organization: AT&T Broadband Date: Tue, 25 Feb 2003 02:57:21 GMT Xref: archiver1.google.com comp.lang.ada:34545 Date: 2003-02-25T02:57:21+00:00 List-Id: "prashna" wrote in message news:d40d7104.0302232240.2681e8e5@posting.google.com... > > If you are absolutely certain the variable will not be referenced after the > ^^^^^ > > lifetime of the procedure or function in which it is declared> > > Hi Steve, > This sentence is bit confisung for me.I am not sure you are talking > about which variable. Are talking about BUFSIZE (or P_SIZE). Both > these variables are local to function X and it is absolutely > impossible to refer these variables outside X.Please clarify this. > And also please let me know how it is risky if I use > 'Unchecked_Access. > The simplest answer is an example of what to NOT do: with Ada.Integer_Text_IO; with Ada.Text_Io; procedure Counter_Example is type my_record is record value : Integer; end record; type my_record_acc is access all my_record; procedure Nested( acc : out my_record_acc ) is local_value : aliased my_record; begin local_value.value := 42; acc := local_value'unchecked_access; end Nested; rec_acc : my_record_acc; begin Nested( rec_acc ); Ada.Text_Io.Put( "Value is: " ); Ada.Integer_Text_Io.Put( rec_acc.value ); Ada.Text_Io.New_Line; end Counter_Example; In this example the value returned from "Nested" is an access to "local_value". But on return from "Nested", "local_value" no longer exists. In this example the value contained in the no-longer valid local_value access is displayed. On my system the resulting output is: Value is: 11 The key I am trying to illustrate is that access to local variables are no longer valid after the procedure or function in which they are declared have returned. Saving one of these "pointers" in a data structure that has a lifetime longer than the procedure or function means the pointer will not be valid when the procedure or function returns. If you are certain that this condition will never happen, everything will be ok. I hope this helps, Steve (The Duck) > Thanks in Advance > Ashwath