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.7 required=5.0 tests=BAYES_00,INVALID_DATE, PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,329032975b221f1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-29 23:51:36 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!noc.near.net!inmet!dsd!stt From: stt@dsd.camb.inmet.com (Tucker Taft) Subject: Re: Q: common types?! Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: <36c1c0$lve@pong.lasc.lockheed.com> Date: Thu, 29 Sep 1994 15:35:21 GMT Date: 1994-09-29T15:35:21+00:00 List-Id: In article <36c1c0$lve@pong.lasc.lockheed.com>, Tony Leavitt wrote: >I have a question for all you Ada wizards. I do not have a lot of experience >with Ada (only about 3000 lines), and I have begun to start making a common >types package. This package would define all kinds of types for feet, nautical >miles, degrees, radians, etc, ad nuasium, for all different kinds and sizes >of float and integers. Am I about to go insane by trying this? Or, does >this exist already on the Internet somewhere? If I was to attempt to do this >how would you recommend about doing it? You could simplify your life by making some of this a generic package, to be instantiated with the "base" floating point type and/or integer type of interest. Put all of the various miles, feet, degrees, etc. in such a generic package. Put the general constants into a separate package. Finally, if you really feel the need, put the numeric types into a third package, with appropriate instantiations of your generic. However, I recommend against this if you can avoid it. Having a centralized "types" package is not a wise way to organize an Ada program, IMHO. You should declare types with the operations that operate on them, in their own package. Grouping them all into one giant package is a way to create maintenance, portability, and general software engineering nightmares. >Here is a sample of what I started to do: > >package Common_Types is > > type float64 is new float ; > for float64'SIZE use 64 ; > type float32 is new float ; > for float32'SIZE use 32 ; > > type integer64 is new integer ; > for integer64'SIZE use 64 ; > type integer32 is new integer ; > for integer32'SIZE use 32 ; > type integer16 is new integer ; > for integer16'SIZE use 16 ; > type integer8 is new integer ; > for integer8'SIZE use 8 ; As someone else pointed out, the above will never work in Ada. You can't turn a 32-bit integer into an 8-bit integer by just squeezing the bits a bit. You have got to impose a range constraint as well, at which point you should declare the range when you declare the type, as follows: type integer64 is range -2**63 .. 2**63-1; type integer32 is range -2**31 .. 2**31-1; type integer16 is range -2**15 .. 2**15-1; type integer8 is range -2**7 .. 2**7-1; Similarly for floating point: type float64 is digits 15; type float32 is digits 6; Note that in Ada 9X, the language-defined package Interfaces already has these. > ... >Tony Leavitt > >Lockheed Aeronautical Systems Company >Marietta, GA 30063-0670 >Voice: (404) 494-7648, Fax:(404) 494-6989 >Email: tony@gelac.lasc.lockheed.com -Tucker Taft