From: alex@MIMSY.CS.UMD.EDU (Alex Blakemore)
Subject: Re: What's the difference between...
Date: 13 Feb 93 05:30:23 GMT [thread overview]
Message-ID: <64238@mimsy.umd.edu> (raw)
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
next reply other threads:[~1993-02-13 5:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-02-13 5:30 Alex Blakemore [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-02-16 17:34 What's the difference between John Bollenbacher
1993-02-16 16:17 enterpoop.mit.edu!ira.uka.de!scsing.switch.ch!sicsun!disuns2!lglsun!kipfe
1993-02-16 15:03 Robert I. Eachus
1993-02-15 13:24 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!haven.umd.ed
1993-02-15 1:55 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!portal!cup.portal
1993-02-14 19:55 Adam Beneschan
1993-02-14 3:08 agate!spool.mu.edu!sdd.hp.com!portal!cup.portal.com!R_Tim_Coslet
1993-02-13 19:18 agate!spool.mu.edu!hri.com!noc.near.net!inmet!spock!stt
1993-02-12 23:57 Mark A Biggar
1993-02-12 23:51 kronos.arc.nasa.gov!butch!LMSC5.IS.LMSC.LOCKHEED.COM!LJ10891
1993-02-12 22:58 Robert I. Eachus
1993-02-12 18:52 Kenneth Anderson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox