|
Prev: libre.adacore.com broken?
Next: generic package with procedure paramter gives "not subtype conformant with declaration"
From: Dmitry A. Kazakov on 30 Sep 2006 15:46 The following does not work in GCC 4.1.1 (20060525), as well as in 3.15p ----------------- with Ada.Unchecked_Conversion; with Ada.Text_IO; use Ada.Text_IO; with System; use System; procedure Test_String_Ptr is type Ptr is access String; function To_Addr is new Ada.Unchecked_Conversion (Ptr, Address); function To_Ptr is new Ada.Unchecked_Conversion (Address, Ptr); X : Ptr; Y : Ptr; Addr : Address; begin X := new String'("A"); Addr := To_Addr (X); Y := To_Ptr (Addr); Put_Line (Y.all); Y := To_Ptr (Addr); Put_Line (Y.all); Y := To_Ptr (Addr); Put_Line (Y.all); Put_Line ("It must have been three lines ""A"""); end Test_String_Ptr; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Jeffrey R. Carter on 30 Sep 2006 21:21 Dmitry A. Kazakov wrote: > The following does not work in GCC 4.1.1 (20060525), as well as in 3.15p Why should it? There's no guarantee that unchecked conversion between access values and System.Address will give meaningful results. Use System.Address_To_Access_Conversions. -- Jeff Carter "Sir Lancelot saves Sir Gallahad from almost certain temptation." Monty Python & the Holy Grail 69
From: Dmitry A. Kazakov on 1 Oct 2006 04:00 On Sun, 01 Oct 2006 01:21:22 GMT, Jeffrey R. Carter wrote: > Dmitry A. Kazakov wrote: >> The following does not work in GCC 4.1.1 (20060525), as well as in 3.15p > > Why should it? There's no guarantee that unchecked conversion between > access values and System.Address will give meaningful results. See ARM 13.9 (17), which requires reversibility of Unchecked_Conversion. That is clearly violated in the example given. Though it is legal not to provide address to access type conversion through Unchecked_Conversion, it is still illegal to provide it wrong. > Use System.Address_To_Access_Conversions. Address_To_Access_Conversions serves a different purpose. It declares a new access type, moreover it is a general access type. BTW, when Address_To_Access_Conversions is composed with an access to access type conversion, the problem persists (it is a bug after all (:-)) Replace To_Ptr and To_Addr with: package Clutter is new Address_To_Access_Conversions (String); function To_Addr (X : Ptr) return Address is begin return Clutter.To_Address (X.all'Unchecked_Access); end To_Addr; function To_Ptr (X : Address) return Ptr is function Cast is new Ada.Unchecked_Conversion (Clutter.Object_Pointer, Ptr); begin return Cast (Clutter.To_Pointer (X)); end To_Ptr; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Jeffrey R. Carter on 1 Oct 2006 15:23 Dmitry A. Kazakov wrote: > > See ARM 13.9 (17), which requires reversibility of Unchecked_Conversion. > That is clearly violated in the example given. Though it is legal not to > provide address to access type conversion through Unchecked_Conversion, it > is still illegal to provide it wrong. It doesn't require it; it merely advises it, and then only "where this clause defines the result". "This clause defines the result" only when "The representation of S is a representation of an object of the target subtype". That is not necessarily true in your case. So lack of reversibility is not an error, even for a compiler that adheres to this advice. > Address_To_Access_Conversions serves a different purpose. It declares a new > access type, moreover it is a general access type. That it defines its own access type is a design error, I agree, but not a serious one. Rather than define your own access type, you use the one defined by the instance of the package. -- Jeff Carter "Monsieur Arthur King, who has the brain of a duck, you know." Monty Python & the Holy Grail 09
From: Frank J. Lhota on 1 Oct 2006 18:33
"Jeffrey R. Carter" <spam.not.jrcarter(a)acm.not.spam.org> wrote in message news:OAUTg.1003007$084.622552(a)attbi_s22... > Dmitry A. Kazakov wrote: >> Address_To_Access_Conversions serves a different purpose. It declares a >> new >> access type, moreover it is a general access type. > > That it defines its own access type is a design error, I agree, but not a > serious one. Rather than define your own access type, you use the one > defined by the instance of the package. The reason why Address_To_Access_Conversions declares its own access type is to make sure that the access values used in these conversions are not "fat pointers". In other words, this design was chosen precisely to avoid the sort of problems exhibited in Test_String_Ptr. |