comp.lang.ada
 help / color / mirror / Atom feed
* Type Conversion in an Assignment Statement
@ 2001-06-18  8:15 Carsten Freining
  2001-06-18  9:27 ` [comp.lang.ada] " David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Carsten Freining @ 2001-06-18  8:15 UTC (permalink / raw)


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

----------------------------------------------------------------------------






^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2001-06-19 12:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-18  8:15 Type Conversion in an Assignment Statement Carsten Freining
2001-06-18  9:27 ` [comp.lang.ada] " David C. Hoos, Sr.
2001-06-18 10:18   ` 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

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