comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Storage space question
Date: 1998/12/11
Date: 1998-12-11T00:00:00+00:00	[thread overview]
Message-ID: <m31zm7o4lm.fsf@mheaney.ni.net> (raw)
In-Reply-To: 36704ADB.73FA308D@pwfl.com

Marin David Condic <condicma@bogon.pwfl.com> writes:

> I've done exactly this in any number of situations. Enumerations are
> definitely "The Ada Way" of solving this problem, so naturally you want
> to try to do this. 

I don't necessarily agree.  Giving enumeration types a representation
clause seems to be of dubious value.

> If you can't find an answer in the compiler-specific documentation, you
> can always get there through the
> less-desirable-but-no-worse-than-C-does-it method of declaring a bunch
> of named numbers:
> 
> Some_Name : constant := 2#0101# ;

But that's going too far, because you've turned off all the type
checks.  

A middle position between named numbers and enumeration types is
constants of a integer type:

  type Robot_Control is range 0 .. 3;

  Run_Robot : constant Robot_Control := 0;

  Stop_Robot : constant Robot_Control := 1;

  Turn_Robot : constant Robot_Control := 3;


  type Control_Register is
    record
      ...
      Control : Robot_Control;
      ...
   end record;


As long as you only use the constants (not the literals), you get all
the type safety that an enumeration type buys you.

Which is why rep clauses for enumeration types is overkill, that adds
unnecessary complexity to the language.







  parent reply	other threads:[~1998-12-11  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-10  0:00 Storage space question Craig Allen
1998-12-10  0:00 ` dennison
1998-12-10  0:00 ` Marin David Condic
1998-12-10  0:00   ` Pat Rogers
1998-12-10  0:00     ` dennison
1998-12-10  0:00       ` Pat Rogers
1998-12-10  0:00   ` Tucker Taft
1998-12-10  0:00     ` callen
1998-12-10  0:00       ` Marin David Condic
1998-12-10  0:00         ` Tucker Taft
1998-12-11  0:00           ` dennison
1998-12-11  0:00         ` Matthew Heaney [this message]
1998-12-11  0:00           ` Marin David Condic
1998-12-12  0:00             ` Matthew Heaney
1998-12-12  0:00               ` David C. Hoos, Sr.
1998-12-12  0:00                 ` Matthew Heaney
1998-12-14  0:00                 ` dennison
1998-12-10  0:00       ` dennison
1998-12-11  0:00       ` Matthew Heaney
1998-12-10  0:00   ` Matthew Heaney
1998-12-10  0:00     ` dennison
replies disabled

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