comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst@cts.com>
Subject: Re: how do i include 111111 in an enumaration type ?
Date: 1999/10/11
Date: 1999-10-11T00:00:00+00:00	[thread overview]
Message-ID: <yeczoxpdwri.fsf@king.cts.com> (raw)
In-Reply-To: slrn80495c.2a2.aidan@skinner.demon.co.uk

aidan@skinner.demon.co.uk (Aidan Skinner) writes:
> On Mon, 11 Oct 1999 13:05:39 -0400, Matthew Heaney
> <matthew_heaney@acm.org> wrote: 
> >The latter technique is preferred if you're tempted to use an
> >enumeration rep clause (don't use enum rep clauses).
> 
> Just out of curiosity, why not? I've had a couple of examples where an
> optional number of boolean parameters have been passed to a
> subprogram, and using an enumeration type would clarify things instead
> of having:
> 
>    foo (thingy, doodah => True, wotsit => False);
> 
> it would be 
> 
>    foo (thingy, doodah, no_wotsit);
> 
> obviously doodah and wotsit have default values.

Ok, no problem so far.  (Personally, I find "doodah => True, wotsit =>
False" clearer, but that's a matter of taste and style.  Also, the
default value for doodah doesn't do you any good if you want to pass a
non-default value for wotsit; you have to either specify both, or use
named notation.)

> It would then seem sensible to use a representation clause to turn the
> two value enumeration types to be 1 bit each (or whatever size your
> implementation of boolean or whatever is).

By "enumeration representation clause", we mean specifically the kind
of representation clause that specifies the internal representation of
each literal of an enumeration type.  See section 13.4 of the Ada 95
RM.  The problem is that the language provides no decent way to get at
the representation once you've defined it; the type has to work
(almost) as if the enumeration representation clause weren't there.
We discussed this here a few weeks ago; see deja.com (formerly known
as DejaNews) for details.

There's nothing wrong with using a size clause on an enumeration type:

    type doodah_type is (no_doodah, doodah);
    for doodah_type'size use 1;

if that's what you need.  On the other hand, for the suggested usage,
there's no reason for a size clause.  Let the compiler figure out how
best to represent a doodah_type object.  Specifying a 1-bit size for a
type doesn't mean that objects of that type will be allocated 1 bit --
which is fortunate, because byte-size or word-sized objects make for
much more efficient code.

Most of the time, it's best just to tell the compiler what you want as
clearly as possible, and let if figure out how best to give it to you.
That's its job.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
"Oh my gosh!  You are SO ahead of your time!" -- anon.




  parent reply	other threads:[~1999-10-11  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7tsq3o$92p$1@minus.oleane.net>
1999-10-12  0:00 ` how do i include 111111 in an enumaration type ? Nick Roberts
1999-10-14  0:00   ` Sybs ALHABSHI
     [not found] ` <38021792_4@news1.prserv.net>
     [not found]   ` <slrn80495c.2a2.aidan@skinner.demon.co.uk>
1999-10-11  0:00     ` Keith Thompson [this message]
1999-10-12  0:00   ` Sybs ALHABSHI
1999-10-12  0:00     ` Matthew Heaney
1999-10-12  0:00       ` Ehud Lamm
1999-10-12  0:00     ` Lutz Donnerhacke
1999-10-12  0:00       ` Matthew Heaney
1999-10-12  0:00         ` Lutz Donnerhacke
1999-10-12  0:00           ` Ted Dennison
1999-10-12  0:00           ` Ted Dennison
1999-10-13  0:00             ` Lutz Donnerhacke
1999-10-13  0:00               ` Matthew Heaney
1999-10-13  0:00                 ` Ted 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