From: "John G. Volan" <johnv@ac3i.dseg.ti.com>
Subject: Re: Beware: Rep spec on an enumeration type causes code explosion
Date: 1997/12/11
Date: 1997-12-11T00:00:00+00:00 [thread overview]
Message-ID: <3490252D.6B550F17@ac3i.dseg.ti.com> (raw)
In-Reply-To: 348F3DFC.10DB@nospam.flash.net
Ken Garlington wrote:
>
> One of the nice things about "holey" representations in Ada, when used
> for
> interfacing to external systems, is the use of 'Valid to check for valid
> input
> data in a very readable manner. However, I would convert the raw input
> to a non-holey type after the check, using either a map or case
> statement
> (depending upon the compiler).
There is no need for anything so elaborate. Just derive a holey
enumeration type from a contiguous enumeration type. Then you can simply
use ordinary Ada type-conversions, and the compiler will implicitly do
the mapping for you:
with Ada.Text_IO;
procedure Holey_Enum_Demo is
type Contiguous_Type is (A, B, C, D, E);
-- *no* rep spec!
type Holey_Type is new Contiguous_Type;
for Holey_Type use (A => 1, B => 2, C => 4, D => 8, E => 16);
Contiguous : Contiguous_Type := A;
Holey : Holey_Type := B;
begin
Contiguous := Contiguous_Type (Holey);
-- implicitly does equivalent of 'Pos
Holey := Holey_Type (Contiguous);
-- implicitly does equivalent of 'Val
end Holey_Enum_Demo;
My feeling is that "holey" enumeration types (like other Chapter 13
features) should really only be used at the "edges" of a program,
wherever you're immediately reading from or writing to some external
system that is expecting a certain data format. Contiguous enumeration
types should be used internally everywhere else in your program, for all
the efficiency reasons that have been ... enumerated :-) ... in this
thread. Luckily, Ada provides this convenient way of converting between
holey and contiguous representations.
--
Internet.Usenet.Put_Signature
(Name => "John G. Volan",
Employer => "Raytheon/TI Advanced C3I Systems, San Jose, CA",
Work_Email => "jvolan@ti.com",
Home_Email => "johnvolan@sprintmail.com",
Slogan => "Ada95: World's *FIRST* International-Standard OOPL",
Disclaimer => "My employer never defined these opinions, so using " &
"them would be totally erroneous...or is that just " &
"nondeterministic behavior now? :-) ");
next prev parent reply other threads:[~1997-12-11 0:00 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-12-05 0:00 Beware: Rep spec on an enumeration type causes code explosion Joe Gwinn
1997-12-06 0:00 ` Robert Dewar
1997-12-08 0:00 ` Joe Gwinn
1997-12-09 0:00 ` Stanley R. Allen
1997-12-06 0:00 ` Robert Dewar
1997-12-06 0:00 ` Ken Garlington
1997-12-06 0:00 ` Corey Minyard
1997-12-08 0:00 ` Joe Gwinn
1997-12-10 0:00 ` Robert Dewar
1997-12-06 0:00 ` Kevin D. Heatwole
[not found] ` <dewar.881478386@merv>
1997-12-07 0:00 ` Robert Dewar
1997-12-09 0:00 ` Jim Gleason
1997-12-06 0:00 ` David Marshall
1997-12-06 0:00 ` Tucker Taft
1997-12-06 0:00 ` Robert Dewar
1997-12-06 0:00 ` Robert Dewar
1997-12-08 0:00 ` Joe Gwinn
1997-12-08 0:00 ` Mats Weber
1997-12-09 0:00 ` Geert Bosch
1997-12-10 0:00 ` Robert Dewar
1997-12-09 0:00 ` Tucker Taft
1997-12-09 0:00 ` Matthew Heaney
1997-12-10 0:00 ` Charles Hixson
1997-12-10 0:00 ` Jean-Pierre Rosen
1997-12-10 0:00 ` Robert Dewar
1997-12-10 0:00 ` Stanley R. Allen
1997-12-14 0:00 ` Robert Dewar
1997-12-10 0:00 ` Stephen Leake
1997-12-14 0:00 ` Robert Dewar
1997-12-10 0:00 ` Ken Garlington
1997-12-11 0:00 ` John G. Volan [this message]
1997-12-11 0:00 ` Ken Garlington
1997-12-12 0:00 ` Matthew Heaney
1997-12-12 0:00 ` Ken Garlington
1997-12-16 0:00 ` John G. Volan
1997-12-17 0:00 ` Ken Garlington
1997-12-12 0:00 ` Alan E & Carmel J Brain
1997-12-12 0:00 ` Robert Dewar
1997-12-15 0:00 ` Tucker Taft
1997-12-16 0:00 ` Brian Rogoff
1997-12-12 0:00 ` Joe Gwinn
1997-12-12 0:00 ` Robert Dewar
1997-12-16 0:00 ` John G. Volan
1997-12-17 0:00 ` Ken Garlington
1997-12-17 0:00 ` Joe Gwinn
1997-12-17 0:00 ` John G. Volan
1997-12-18 0:00 ` Joe Gwinn
1997-12-11 0:00 ` Rakesh Malhotra
1997-12-11 0:00 ` Matthew Heaney
1997-12-12 0:00 ` Robert Dewar
1997-12-12 0:00 ` Samuel Tardieu
1997-12-12 0:00 ` Robert Dewar
1997-12-12 0:00 ` Rakesh Malhotra
1997-12-14 0:00 ` Alan E & Carmel J Brain
1997-12-12 0:00 ` Joe Gwinn
1997-12-15 0:00 ` Robert Dewar
1997-12-16 0:00 ` Joe Gwinn
1997-12-16 0:00 ` Robert Dewar
1997-12-06 0:00 ` Robert Dewar
1997-12-06 0:00 ` Matthew Heaney
1997-12-10 0:00 ` GNORT information ( Was Re: Beware: Rep spec on an enumeration type causes code explosion ) Mark Bennison
1997-12-10 0:00 ` Robert Dewar
1997-12-06 0:00 ` Beware: Rep spec on an enumeration type causes code explosion Robert Dewar
1997-12-06 0:00 ` Robert Dewar
1997-12-08 0:00 ` Joe Gwinn
1997-12-07 0:00 ` Larry Kilgallen
-- strict thread matches above, loose matches on Subject: below --
1997-12-09 0:00 tmoran
1997-12-11 0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-11 0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-11 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox