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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d8c487e59f13ecdf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-09 13:06:31 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uunet!sea.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Ada Basics User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Wed, 9 Oct 2002 20:05:21 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:29640 Date: 2002-10-09T20:05:21+00:00 List-Id: vashwath@rediffmail.com (prashna) writes: > Hi all, > What is the difference between declaring a type by using new (ex type > one_to_hundred is new Integer range 1..100) and declaring a type > without using new (type one_to_hundred is range 1..100)? There is *almost* no difference. I would usually choose the latter, if the new type has nothing to do with Standard.Integer. The only semantic difference is in the base range. In the former case, One_To_Hundred'Base'Last = Integer'Last, whereas in the latter case, One_To_Hundred'Base'Last >= 100. The base range matters for intermediate expression results, so: X: One_To_Hundred := 100; Y: One_To_Hundred := 100; Z: One_To_Hundred := 100; W: One_To_Hundred := (X + Y + Z) / 3; we have an intermediate result equal to 300. In the latter case, the implementation *could* raise Constraint_Error (if it chose the base range to be, say, -128..127). In the former case, C_E cannot be raised, because we know Standard.Integer'Last is at least 32,767, and most likely 2 billion, or more. You could also guarantee that W = 100 (rather than raising C_E) like this: type Intermediate is range -300..300; subtype One_To_Hundred is Intermediate range 1..100; But if you don't have intermediate expression results that lie outside the bounds of the type, then both of the above are equivalent, and if all you care about is the 1..100 range, then "type T is range 1..100" is probably the best style. - Bob