comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: type and subtype
Date: Sun, 24 Jul 2005 16:40:26 GMT
Date: 2005-07-24T16:40:26+00:00	[thread overview]
Message-ID: <_vPEe.3516$Uk3.77@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <87mzocrx9d.fsf@insalien.org>

Ludovic Brenta wrote:
> 
> Two subtypes of the same type are compatible with one another.  One
> can convert between them using an implicit type conversion (i.e. no
> special syntax required).

There is no type conversion between subtypes of the same type, since 
they are the same type. There are checks that the value of the source 
matches the constraints of the destination.

Consider:

type Year_Number is range 1901 .. 2099;
type Month_Number is range 1 .. 12;

Y : Year_Number := 2000;
M : Month_Number := 6;

procedure P (Y : in Year_Number);

...

Y := M; -- illegal, different types
P (Y => Y + M); -- illegal, no such "+"

and then:

subtype Year_Number is Integer range 1901 .. 2099;
subtype Month_Number is Integer range 1 .. 12;

Y : Year_Number := 2000;
M : Month_Number := 6;

procedure P (Y : in Year_Number);

...

Y := M; -- legal, same type
P (Y => Y + M); -- legal, "+" (Left, Right : Integer) return Integer;
                 -- Y + M in Year_Number

M := 12;
M := 2 * M - M; -- legal, operations evaluated for type (Integer)
                 -- result in Month_Number

-- 
Jeff Carter
"I like it when the support group complains that they have
insufficient data on mean time to repair bugs in Ada software."
Robert I. Eachus
91



  reply	other threads:[~2005-07-24 16:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-24 14:24 type and subtype Douglas Chong
2005-07-24 14:39 ` Dmitry A. Kazakov
2005-07-25 17:07   ` Martin Krischik
2005-07-24 16:20 ` Ludovic Brenta
2005-07-24 16:40   ` Jeffrey Carter [this message]
2005-07-25  8:23     ` Dmitry A. Kazakov
2005-07-25 15:41       ` Jeffrey Carter
2005-07-25 21:59         ` Ludovic Brenta
2005-07-26  8:21         ` Dmitry A. Kazakov
2005-07-25 17:02 ` Martin Krischik
replies disabled

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