From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Types, subtypes and ranges
Date: Mon, 12 Mar 2001 05:57:57 -0600
Date: 2001-03-12T11:56:57+00:00 [thread overview]
Message-ID: <98idi9$66g$1@hobbes2.crc.com> (raw)
In-Reply-To: V4%q6.26$OG2.2999@read2.inet.fi
Because TTT'Image is inherited from its base type T.
If you had declared TT and TTT as new T types, the constraint
error would have occurred, but then you wouldn't have been
able to add anders to banders without type conversion, because
the types would have been distinct.
"Anders Wirzenius" <anders.wirzenius@pp.qnet.fi> wrote in message
news:V4%q6.26$OG2.2999@read2.inet.fi...
>
> Mark Lundquist wrote in message ...
> >Sorry for the late response (I lost access to news for a while...)
> >
> >WM <wwminirl@hotmail.com> wrote in message
> >news:97pfmt$ll30@tech.port.ac.uk...
> >> Hi, I am an ada beginner. Can anyone kindly tell me what's the
difference
> >> between TYPE and SUBTYPE?
> >
> ...
> > subtype S is T;
> >
> >declares a new subtype S of the type of subtype T. This is also an
example
> >of a subtype declaration that does not include a constraint, so the
> >constraint of S is the same as the constraint of T. (This is how you
> >"rename" or create an alias for a type). What a subtype declaration
looks
> >like that adds a constraint depends on the type of the subtypes, e.g. for
> an
> >integer type you might have
>
> May I continue with two more questions:
> 1.
> given
> >
> > subtype S is T range 1 .. 10;
>
> what is the the difference between the above declaration and
> type S is new T range 1..10;
>
> 2.
> Why don't I get a constraint_error in the following code where I violate
the
> range of type TTT in the Put statement?
>
> with Ada.Text_IO;
> procedure Why_Not_Constraint_Error is
> type T is new Integer;
> subtype TT is T range -2..-1;
> subtype TTT is T range -1..-1;
> anders : TT := -2;
> bnders : TTT := -1;
> use Ada.Text_IO;
> begin
> Put ( TTT'Image ( anders+bnders ) );
> end Why_Not_Constraint_Error;
>
> Anders
> another beginner
>
>
>
next prev parent reply other threads:[~2001-03-12 11:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-03 1:00 Questions: WM
2001-03-03 3:30 ` Questions: Robert Love
2001-03-03 11:09 ` Questions: David C. Hoos, Sr.
2001-03-07 23:05 ` Questions: Mark Lundquist
2001-03-08 1:14 ` Questions: Robert A Duff
2001-03-12 7:41 ` Types, subtypes and ranges Anders Wirzenius
2001-03-12 11:57 ` David C. Hoos, Sr. [this message]
2001-03-12 16:06 ` Tucker Taft
2001-03-13 6:40 ` Anders Wirzenius
2001-03-12 16:57 ` Scott Ingram
2001-03-18 22:28 ` Lao Xiao Hai
2001-03-19 13:22 ` Marc A. Criley
2001-03-20 16:57 ` Lao Xiao Hai
-- strict thread matches above, loose matches on Subject: below --
2001-03-14 13:50 Christoph Grein
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox