Re: type and subtype



Dmitry A. Kazakov wrote:

I think that Ludovic's view is more consistent: checks are just a part of the conversion which otherwise is an identity function, because *presently* the representation is required to be same. But representation is an implementation detail and thus cannot count. Moreover it is very desirable to allow subtypes having different representations.

Try this with your favorite compiler:

Ada.Text_IO.Put_Line
   (Item => "Integer'Size =" & Integer'Image (Integer'Size) ):
Ada.Text_IO.Put_Line
   (Item => "Natural'Size =" & Integer'Image (Natural'Size) ):

You're likely to get something like

Integer'Size = 32
Natural'Size = 31

because representations of subtypes are not required to be the same.

We can also consider

type Rec (Length : Positive) is record
   V : String (1 .. Length);
end record;

subtype Small is Rec (Length =>     1);
subtype Big   is Rec (length => 1_000);

where Small and Big have significantly different representations. Then there are subtypes of variant record types with discriminants that select different variants.
begin:vcard
fn:Jeffrey Carter
n:;Jeffrey Carter
email;internet:jeffrey_r_carter-nr [commercial-at] raytheon [period | full stop] com
x-mozilla-html:FALSE
version:2.1
end:vcard



Relevant Pages

  • Re: How to put 200 into an integer sub-type of 16 bits (code included)
    ... right to put their own restrictions on representation items. ... Nothing about specifying it for non-first subtypes. ... but the second sentence of ...
    (comp.lang.ada)
  • Re: How to put 200 into an integer sub-type of 16 bits (code included)
    ... specific aspects may differ for different subtypes of the same type". ... that says that "Size and Alignment clauses" are subtype-specific ... paragraph are about representation items, ...
    (comp.lang.ada)
  • Re: type and subtype
    ... >> Two subtypes of the same type are compatible with one another. ... >> can convert between them using an implicit type conversion (i.e. no ... > matches the constraints of the destination. ... the representation is required to be same. ...
    (comp.lang.ada)
  • Re: Ada to Interfacing C# (Urgent)
    ... mistake, actually it should be pragma Convention. ... Jeffrey R. Carter wrote: ... tells the compiler to use the same representation for ... For access types, they will be ...
    (comp.lang.ada)