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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,25ab365b646cef74 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access Reply-To: no to spamers (No@email.given.org) References: <7053ea09-38cd-4e30-9827-a1384bafd190@p31g2000prf.googlegroups.com> <37Ppk.5180$Mh5.1917@bgtnsc04-news.ops.worldnet.att.net> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Sun, 17 Aug 2008 19:47:24 GMT NNTP-Posting-Host: 12.64.102.205 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1219002444 12.64.102.205 (Sun, 17 Aug 2008 19:47:24 GMT) NNTP-Posting-Date: Sun, 17 Aug 2008 19:47:24 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:1639 Date: 2008-08-17T19:47:24+00:00 List-Id: Addition: The problem is that local data is stored on the primary stack and if an error is encounter the exception handlers could remove the local data off the stack, creating a 'dangling references.'. Which would makes the pointer (Access variable) invalid or unsafe. So, you must use the "Unchecked_Access" for local data and the programmer is responsible for catching any exceptions or other conditions that might cause a 'dangling reference.' Also, because of the specs refering to "Access" and "Unchecked_Access" in both Ada_95 and Ada_2005 is basically unchanged you can use "Unchecked_Access" instead of "Access" but be warned you must insure the code is safe. And any GNAT that does not support this type of safety should be concerned as corrupt and unusable. PS. As for Ada-83, the answer is no! "Unchecked_Access" was added during the creation of Ada-95. In <37Ppk.5180$Mh5.1917@bgtnsc04-news.ops.worldnet.att.net>, anon@anon.org (anon) writes: >If the GNAT compiler follows the RM on "accessibility" rules. Then it >will force you to use the "Unchecked_Access" attribute for any non-local >pointer trying to point to local object". Solution: If possible move the >object to be access to a package global variable (non-local), then you can >use Access attribute. > > >Note: >RM 13.10 (1) => "The attribute Unchecked_Access is used to create access >values in an unsafe manner -- the programmer is responsible for >preventing 'dangling references.' " > > > >In <7053ea09-38cd-4e30-9827-a1384bafd190@p31g2000prf.googlegroups.com>, Jerry writes: >>I have a curious report from two members of the development team for >>PLplot, a popular plotting package for which I have written bindings >>in Ada. The project is mature enough that the team decided to enable >>Ada by default when building, so I am concerned about the following e- >>mail. >> >>========== begin e-mail ============ >> >> >> >>This latest change to the Ada bindings causes a build error for me >>with gnat 4.2.3 on Ubuntu. >> >>plplot.adb:2751:37: non-local pointer cannot point to local object >>The offending line is >> PL_Pen_Labels(Index) := Temp_C_String'Unchecked_Access; >> >> >> >>This must depend on the version of gnat since I don't see this error >>for gnat 4.3.1-2 from Debian testing (and I presume Jerry didn't see >>it for his gnat-4.3 version as well). >> >>========= end e-mail ============== >> >>I (Jerry) in fact did not see a problem on my OS X 4.3 compiler. >> >>I could supply more details of the code and might even try to write a >>small program but testing on someone else's machine would be a bit >>tedious. BUT--this error makes no sense to me--I would expect to (and >>_do_) see this error if the line in question is >> >> PL_Pen_Labels(Index) := Temp_C_String'Access; >> >>The whole purpose of using Unchecked_Access is to make this error go >>away. It this a known problem on 4.2.3 Unbutu? Is it a compiler error? >>Why does it work as expected on my 4.3 OS X, on 4.3.1-2 Debian >>testing, but not 4.2.3 Ubuntu? >> >>Jerry >