comp.lang.ada
 help / color / mirror / Atom feed
From: "Ludovic Brenta" <ludovic@ludovic-brenta.org>
Subject: Re: Compare these two (sub)type declarations
Date: 4 Jul 2006 03:25:38 -0700
Date: 2006-07-04T03:25:38-07:00	[thread overview]
Message-ID: <1152008738.616133.149850@m79g2000cwm.googlegroups.com> (raw)
In-Reply-To: <1152006378.935306.287820@m79g2000cwm.googlegroups.com>

Lance writes :
> What is the difference between these two declarations?
>
> subtype Foo is Integer;

Foo is a subtype. It is compatible with Integer and with all other
subtypes of Integer such as Natural and Positive, i.e. you can convert
implicitly between all these subtypes. The compiler inserts range
checks where appropriate.

> and
>
> type Bar is new Integer;
>
> In fact, what _is_ the second declaration? Would variables of type Bar
> not be allowed in expressions where Integers are expected?

Bar is a derived type. It is not compatible with Integer, or with any
subtype of Integer, so the compiler would reject a program that passes
a Bar to a subprogram that expects an Integer. You can, however,
convert _explicitly_ between Bar and Integer, just like between any two
numeric types; the compiler inserts range checks as appropriate.

HTH
 
> Jerry

Is it Lance, or Jerry now?

-- 
Ludovic Brenta.




  reply	other threads:[~2006-07-04 10:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-04  9:46 Compare these two (sub)type declarations Lance
2006-07-04 10:25 ` Ludovic Brenta [this message]
2006-07-04 20:01   ` Lance
2006-07-04 21:13     ` spam countermeasures (was: Compare these two (sub)type declarations) Björn Persson
2006-07-05 17:42 ` Compare these two (sub)type declarations 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