comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
To: <comp.lang.ada@ada.eu.org>
Cc: <freining@informatik.uni-jena.de>
Subject: Re: [comp.lang.ada] Type Conversion in an Assignment Statement
Date: Mon, 18 Jun 2001 04:27:29 -0500
Date: 2001-06-18T04:27:29-05:00	[thread overview]
Message-ID: <mailman.992856502.8871.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 3B2DB8B9.1A26F90F@informatik.uni-jena.de

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" <freining@informatik.uni-jena.de>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
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
>




  reply	other threads:[~2001-06-18  9:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-18  8:15 Type Conversion in an Assignment Statement Carsten Freining
2001-06-18  9:27 ` David C. Hoos, Sr. [this message]
2001-06-18 10:18   ` [comp.lang.ada] " Carsten Freining
2001-06-18 10:18   ` Carsten Freining
2001-06-18 13:28 ` Ted Dennison
2001-06-19  5:23   ` Carsten Freining
2001-06-18 20:08 ` Robert A Duff
2001-06-19  5:41   ` Carsten Freining
2001-06-19 12:35     ` Underscore Usage (was: Type Conversion in an Assignment Statement) Wilhelm Spickermann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox