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 X-Google-Thread: 103376,e26ffba340697f29,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-18 01:14:05 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!193.174.75.178!news-fra1.dfn.de!news-lei1.dfn.de!news.uni-jena.de!not-for-mail From: Carsten Freining Newsgroups: comp.lang.ada Subject: Type Conversion in an Assignment Statement Date: Mon, 18 Jun 2001 10:15:53 +0200 Organization: Friedrich-Schiller-University Jena, Germany Message-ID: <3B2DB8B9.1A26F90F@informatik.uni-jena.de> NNTP-Posting-Host: ipc208.inf.uni-jena.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fsuj29.rz.uni-jena.de 992852044 10168 141.35.14.247 (18 Jun 2001 08:14:04 GMT) X-Complaints-To: news@rz.uni-jena.de NNTP-Posting-Date: 18 Jun 2001 08:14:04 GMT X-Mailer: Mozilla 4.73 [de] (WinNT; U) X-Accept-Language: de Xref: archiver1.google.com comp.lang.ada:8831 Date: 2001-06-18T08:14:04+00:00 List-Id: 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 ----------------------------------------------------------------------------