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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,88093378be1184d4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-07 05:32:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: Eric Merritt Newsgroups: comp.lang.ada Subject: Re: A question and a request Date: Wed, 7 Nov 2001 05:24:02 -0800 (PST) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: avanie.enst.fr 1005139514 40819 137.194.161.2 (7 Nov 2001 13:25:14 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 7 Nov 2001 13:25:14 +0000 (UTC) To: comp.lang.ada@ada.eu.org Return-Path: In-Reply-To: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.6 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:15989 Date: 2001-11-07T05:24:02-08:00 I knew I was missing something. That actaully make sense, I guess I was getting this typeing behavior mixed up with the OO inheritence model. Thank You, Eric Merritt --- Preben Randhol wrote: > On Tue, 6 Nov 2001 20:44:19 -0800 (PST), Eric > Merritt wrote: > > As some of you may know I am fairly new to Ada and > I > > just found out something that surprised me. I > declared > > two subtypes of an integer. I was then able to add > > these two types together and assign the result to > an > > instance of one of the above subtypes. or > > > > subtype type_1 is Integer; > > subtype type_2 is Integer; > > > > type_1_instance : type_1; > > type_2_instance : type_2; > > type_1_instance_2 : type_1; > > > > type_1_instance := 1; > > type_2_instance := 2; > > type_1_instance_2 := type_1_instance + > > type_2_instance; > > > > The addition operator is taking two disparate but > > related types and adding them. This is fine, > > up-casting is a normal thing. However, when the > result > > is returned it is not (should not be?) an instance > of > > the subtype. It seems that the compiler is > > down-casting automatically. This bothers me and it > > seams that is violates Ada's strong typing. What > am I > > missing here? > > Use type not subtype if you do not want the above > behavior. Read > below (taken from: > http://goanna.cs.rmit.edu.au/~dale/ada/aln/4_basic_types.htmli > ) > > Subtypes > > We can restrict the range of values a variable can > take by declaring a > subtype with a restricted range of values (this > corresponds to Pascal's > user defined types). Any attempt to place an > out-of-range value into a > variable of a subtype results in an exception > (program error). In this > way program errors can be discovered. The syntax for > a subtype > declaration is > > subtype Name is Base_Type; > subtype Name is Base_Type range lowerbound . . > upperbound; > > Examples of declaring subtypes are given below. > > type Processors is (M68000, i8086, i80386, M68030, > Pentium, PowerPC); > subtype Old_Processors is Processors range > M68000..i8086; > subtype New_Processors is Processors range > Pentium..PowerPC; > > subtype Data is Integer; > subtype Age is Data range 0 . . 140; > subtype Temperatures is Float range -50.0 .. 200.0; > subtype Upper_Chars is Character range 'A' .. 'Z'; > > Subtypes are compatable with their base types . They > can be placed in > the same place as any variable of the base type can. > Also variables of > different subtypes that are derived from the same > base type are > compatable. > > My_Age : Age; > Height : Integer; > > Height := My_Age; -- silly, but never causes a > problem. > > My_Age := Height; -- will cause a problem if > height's > -- value is outside the range of > -- my_age (0..140), but still > -- compilable. > > > Preben > -- > Please, stop bombing civilians in Afghanistan. One > cannot write off > killing innocent children and other civilians as > "collateral damage". > A civilian is a civilian whether he or she is > American or from another > country in the world. > http://web.amnesty.org/11september.htm > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada __________________________________________________ Do You Yahoo!? Find a job, post your resume. http://careers.yahoo.com