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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,e26ffba340697f29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-18 03:18:19 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!opentransit.net!jussieu.fr!enst!enst.fr!not-for-mail From: Carsten Freining Newsgroups: comp.lang.ada Subject: Re: [comp.lang.ada] Type Conversion in an Assignment Statement Date: Mon, 18 Jun 2001 12:18:31 +0200 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: <3B2DB8B9.1A26F90F@informatik.uni-jena.de> Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: avanie.enst.fr 992859498 82017 137.194.161.2 (18 Jun 2001 10:18:18 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Mon, 18 Jun 2001 10:18:18 +0000 (UTC) To: comp.lang.ada@ada.eu.org Return-Path: X-Mailer: Mozilla 4.73 [de] (WinNT; U) X-Accept-Language: de Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:8834 Date: 2001-06-18T12:18:31+02:00 Thank you for your Answer, That was my first try to explain this too. The problem is to find a proof for this within the Ada95 LRM. As you have explained it, it seems that my proof with Chapter 5.2 (11) and (13) and Chapter 4.6 (14) and (16), where the type conversion of the Value of the Expression to the target subtype is explained. Thanks again, Carsten Freining. "David C. Hoos, Sr." schrieb: > If you had declared Pointer to be an access to IntegerSubType, instead > of an Access to Integer, then constraint_error would have been raised. > > Making the assignment to Pointer by means of the new operator does > not change the constraints of the access object "Pointer." > You did not create a new object with the new operator -- instead, you > assigned an access value designating a subytpe of Integer, so that > assignment is legal. > > The Pointer object which was originally designating no value > (i.e. it was null), is still an access-to-Integer object. > > So, the later assignment of 105 to the space designated by > Pointer is still legal. > > ----- Original Message ----- > From: "Carsten Freining" > Newsgroups: comp.lang.ada > To: > Sent: June 18, 2001 3:15 AM > Subject: [comp.lang.ada] Type Conversion in an Assignment Statement > > > Hello, > > > > I have a problem I try to resolve with the Ada95 LRM. I have the > > following lines of code: > > > > type IntegerAccessType is access Integer; > > subtype IntegerSubType is Integer range 1..100; > > Pointer: IntegerAccessType := new IntegerSubType; > > begin > > Pointer.all :=105; > > end; > > > > This code is only to show the problem I have. It is not a real program > > and it is not any recomended programming style. > > > > This is a correct program. I thought it would raise a constraint_error, > > because I created a new object of type IntegerSubType, so the > > Accessvariable Pointer is accessing this specific subtype. But I can > > assign any integer value to this object refered to by the pointer. > > > > Here are my investigations so far in the Ada95 LRM: > > > > 4.8 Allocators > > (3) The expected type for an allocator shall be a single > > access-to-object type whose designated type covers the type determined > > by the subtype_mark of the subtype_indication or qualified_expression. > > > > The result of the new operation is an access-to-object type. The > > object-type of this accesstype shall cover the object-type of the new > > created object. Since it should only cover the created object-type it is > > allowed to choose the designated type larger. > > > > (9) If the designated type is elementary, an object of the designated > > subtype is created and any implicit initial value is assigned; > > > > Since the Designated Type is ELementary, the object has to be created > > from the designated subtype. The LRM is talking about the subtype in any > > case the 'type' can be assigned to a variable. Integer is first a type, > > but if I want to define a variable of type integer, a general subtype of > > type interger is first created. this subtype is then assigned to the > > variable. This means first there is a subtype of the subtype from > > integer created, the object is of type IntegerSubType. > > > > 5.2 Assignement Statement > > > > (11) The value of the expression is converted to the subtype of the > > target. The conversion might raise an exception (see 4.6). > > > > The Value or in this case the object Type of the AccessType will be > > converted to the target type. > > > > (13) The value of the target becomes the converted value. > > > > This seems the evidence, that the target of the assignment will have the > > complete Type (means Object-Type of the Access-to-Object-Type). > > > > We still want to look into 4.6 Type Conversion > > > > And I can only find (14) and 16 here: > > (14) If the target type is an access-to-variable type, then the operand > > type shall be an access-to-variable type; > > (16) If the target designated type is not tagged, then the designated > > types shall be the same, and either the designated subtypes shall > > statically match or the target designated subtype shall be discriminated > > and unconstrained; > > > > That is all I have found so far. I think it is already the evidence, > > that the with the allocator operation new created object, of (with the > > allocator) the designated type is converted into the object-type of the > > Access-to-Object-Type for the access-variable that is the target of the > > assignement statement. Is this correct, or did I miss something. > > > > Regards, > > > > Carsten Freining. > > > > > > -- > > ---------------------------------------------------------------------------- > > > > Carsten Freining > > > > e-Mail: freining@informatik.uni-jena.de > > Tel. 03641 9 46344 > > Adresse: Friedrich-Schiller-Universit�t Jena > > Fakult�t f�r Mathematik & Informatik > > Institut f�r Informatik > > Lehrstuhl f�r Programmiersprachen und Compiler > > D-07740 Jena, Germany > > > > ---------------------------------------------------------------------------- > > > > > > > > _______________________________________________ > > comp.lang.ada mailing list > > comp.lang.ada@ada.eu.org > > http://ada.eu.org/mailman/listinfo/comp.lang.ada > > -- ---------------------------------------------------------------------------- Carsten Freining e-Mail: freining@informatik.uni-jena.de Tel. 03641 9 46344 Adresse: Friedrich-Schiller-Universit�t Jena Fakult�t f�r Mathematik & Informatik Institut f�r Informatik Lehrstuhl f�r Programmiersprachen und Compiler D-07740 Jena, Germany ----------------------------------------------------------------------------