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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,38730e01f356adfa X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news1.google.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.freenet.de!news.tiscali.de!not-for-mail From: Wilhelm Spickermann Newsgroups: comp.lang.ada Subject: Re: types and subtypes Date: Mon, 13 Mar 2006 21:22:16 +0100 Organization: Tiscali Germany Usenet Message-ID: References: <1142251677.837212.109000@i39g2000cwa.googlegroups.com> <1142273325.634632.41020@j52g2000cwj.googlegroups.com> NNTP-Posting-Host: p83.129.18.29.tisdip.tiscali.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: ulysses.news.tiscali.de 1142281336 22635 83.129.18.29 (13 Mar 2006 20:22:16 GMT) X-Complaints-To: abuse@tiscali.de NNTP-Posting-Date: Mon, 13 Mar 2006 20:22:16 +0000 (UTC) User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:3344 Date: 2006-03-13T21:22:16+01:00 List-Id: ada_student@yahoo.com wrote: > A type also defines the set of values that an object can have. There is a difference between the set of values for a variable and the set of values for an expression. That's the key to understanding here. > If an Ada subtype adds a constraint to an Ada type, then the > subtype is a type that is a derivative(derivative as in the Ada > sense) of the Ada type and is different from that type. A subtype is not a type; no constraint is added to the type; the type remains unchanged; no new type is created. As far as simple types like numbers are concerned: A subtype is just a name used to create variables which are restricted to a subset of the possible values of the type. Values/Expressions are not of a subtype -- they just belong to a type. The subtype restrictions only apply, when an assignment to a variable of a subtype is done. If A is a variable of your subtype Count_To_Ten, then you may write " if A*3-8 > 15 then ...". No subtype restrictions are applied to A*3 or A*3-8 or 15. But the information about the restricted set of values for A is used in the optimization -- Integer will not overflow during this computation :-) . Now if you have a variable B of your subtype Positive and you write B := A*3-8, then all computations can be done without problems as all values involved are of type Integer. Only when assigning the result to B, you may get a Constraint_Error. Hope this helps in understanding Wilhelm