comp.lang.ada
 help / color / mirror / Atom feed
From: agate!howland.reston.ans.net!usc!cs.utexas.edu!csc.ti.com!tilde.csc.ti.co m!mksol!strohm@ucbvax.Berkeley.EDU  (john r strohm)
Subject: Re: thoughts on "holey" enumerated types
Date: 12 Sep 93 18:02:59 GMT	[thread overview]
Message-ID: <1993Sep12.180259.2237@mksol.dseg.ti.com> (raw)

In article <1993Sep11.192353.19703@jarvis.csri.toronto.edu> blaak@csri.toronto.
edu (Raymond Blaak) writes:
>The thread on converting integers to a sparse enumerated type has got
>me thinking.
>
>Couldn't enumerated types always be implemented as a contiguous range, such
>that use clauses to specify member ``positions'' just affected the 'POS and
>'VAL functions?

The key word in the above is "always".

The short answer is "No."

The longer answer is "No, because Ada allows the programmer to override
the compiler's default assignment of values to enumerated type names."

>That way enumerated type operations (especially loop traversal over a range,
>or array indexing) can always be efficient.

Loop traversal over a range can be made efficient, by introducing a "hidden"
induction variable that traverses a translation table in the place of the
iterated enumerated type variable.  I would be very surprised to learn that
a production-quality compiler DIDN'T do this.

Array indexing cannot be helped: by definition, when one deposits a value,
what is stored must be the correct bit pattern for the value.  Rep specs
are used to control that bit pattern.  When one later reads the value,
one gets back the same (arbitrary) bit pattern, so one has no option but
to do the translation for the array index.  Good Ada programmers understand
about this and avoid combining enumerated types with rep specs and array
indexing.

             reply	other threads:[~1993-09-12 18:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-09-12 18:02 agate!howland.reston.ans.net!usc!cs.utexas.edu!csc.ti.com!tilde.csc.ti.co [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-13 15:33 thoughts on "holey" enumerated types David Emery
1993-09-13 14:24 john r strohm
1993-09-12 21:51 Michael Feldman
1993-09-12 21:45 Michael Feldman
1993-09-12 20:13 agate!howland.reston.ans.net!noc.near.net!inmet!bobduff
1993-09-11 23:23 cs.utexas.edu!utnut!utcsri!csri.toronto.edu!blaak
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox