From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bfa00be8f7a5ae46 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!m79g2000cwm.googlegroups.com!not-for-mail From: "Ludovic Brenta" Newsgroups: comp.lang.ada Subject: Re: Compare these two (sub)type declarations Date: 4 Jul 2006 03:25:38 -0700 Organization: http://groups.google.com Message-ID: <1152008738.616133.149850@m79g2000cwm.googlegroups.com> References: <1152006378.935306.287820@m79g2000cwm.googlegroups.com> NNTP-Posting-Host: 212.190.145.10 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1152008743 23395 127.0.0.1 (4 Jul 2006 10:25:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 4 Jul 2006 10:25:43 +0000 (UTC) In-Reply-To: <1152006378.935306.287820@m79g2000cwm.googlegroups.com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; SunOS sun4u; fr-FR; rv:1.6) Gecko/20040116,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 SEVPXS01 Complaints-To: groups-abuse@google.com Injection-Info: m79g2000cwm.googlegroups.com; posting-host=212.190.145.10; posting-account=ZjNXewwAAADyBPkwI57_UcX8yKfXWOss Xref: g2news2.google.com comp.lang.ada:5470 Date: 2006-07-04T03:25:38-07:00 List-Id: 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.