comp.lang.ada
 help / color / mirror / Atom feed
From: wdl39!mab@ford-wdl1.arpa  (Mark A Biggar)
Subject: Re: What's the difference between...
Date: 12 Feb 93 23:57:56 GMT	[thread overview]
Message-ID: <1993Feb12.235756.9782@wdl.loral.com> (raw)

In article <9302121052.aa23420@Paris.ics.uci.edu> kanderso@mabillon.ICS.UCI.EDU
 (Kenneth Anderson) writes:
>What is the difference between
>these two type declarations:
>
>type Placement is range 0 .. 10;
>
>subtype Placement is INTEGER range 0 .. 10;
>
>The reason I ask this, is that I have the duty here at U.C. Irvine of teaching
>the students of an Intro to Software Engineering course enough Ada for them
>to do their homework assignments.  I get two 1.5 hour lectures to do this.

Remember that in Ada all type names are really subtype names on an anonymous
type.

The second declaration above specifies that the type of Placement is the same
type as that of INTEGER, or in other words Placement'BASE is the same as
INTEGER'BASE.  Therefore assignment between variables of subtype Placement
and subtype INTEGER are legal with out any explisit type conversion.
Of course a constraint check may be necessary.

For the first declaration you are leaving it up to the compiler to
select the type ('BASE) for Placement. (Note you still only get a subtype)
The compiler may pick INTEGER'BASE or it may pick SHORT_INTEGER'BASE
or even LONG_INTEGER'BASE.  Most compiler pick the smallest type that
contains all the values of the specified constraint.  It then creates
a new anonymous interger type with the same properties as the selected
'BASE type and uses it as the Placement'BASE.  Now as Placement is a
subtype of a different type than the the subtype INTEGER, you must use
an explisit conversion when assigning from one to the other.

--
Mark Biggar
mab@wdl1.wdl.loral.com

             reply	other threads:[~1993-02-12 23:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-02-12 23:57 Mark A Biggar [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-13  5:30 Alex Blakemore
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