From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 13 Feb 93 05:30:23 GMT From: alex@MIMSY.CS.UMD.EDU (Alex Blakemore) Subject: Re: What's the difference between... Message-ID: <64238@mimsy.umd.edu> List-Id: In article <9302121052.aa23420@Paris.ics.uci.edu> kanderso@mabillon.ICS.UCI.EDU (Kenneth Anderson) writes: > these two type declarations: > type Placement is range 0 .. 10; > subtype Placement is INTEGER range 0 .. 10; first remember what a type is (its two things) 1. a _set_ of values 2. a set of operations a whole lot. here's a quick answer. the first one introduces a new numeric type. it is a distinct type from other numeric types and thus you cannot assign the contents integer of an integer variable ot a placement variable without a conversion. this is useful in the abstract to keep apples and oranges separate, even if both can be represented by integral values. the compiler is free to choose any representation that can hold any value of the type - so it will likely choose 1 byte in this case. (it could choose less or more). the type definition (like a derived type) introduces a completely new set of values and operations - though they may be copied from the base type. the second one introduces a subtype of integer. subtypes merely restrict the set of values of a type to a subset. they do not introduce a new set of values and operations. variables of the subtype can be assigned freely to/from objects of the type (or its other subtypes). constraint checks will be made if needed to guarantee the range constraint is satisfied. the compiler must use the same representation for all objects of a type (irregardless of any subtypes) in this case, a placement must take as many bits as any other integer, so the compiler will likely use 4 bytes (say) and not 1 byte for each placement object. this should be a FAQ -- --------------------------------------------------- Alex Blakemore alex@cs.umd.edu NeXT mail accepted