From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bc7fae210b5e1392 X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: how do i include 111111 in an enumaration type ? Date: 1999/10/11 Message-ID: #1/1 X-Deja-AN: 535674406 Sender: kst@king.cts.com References: <7tsq3o$92p$1@minus.oleane.net> <38021792_4@news1.prserv.net> X-Trace: thoth.cts.com 939702754 18801 198.68.168.21 (12 Oct 1999 04:32:34 GMT) Organization: CTS Network Services Newsgroups: comp.lang.ada X-Complaints-To: newsmaster@cts.com Date: 1999-10-11T00:00:00+00:00 List-Id: aidan@skinner.demon.co.uk (Aidan Skinner) writes: > On Mon, 11 Oct 1999 13:05:39 -0400, Matthew Heaney > 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 San Diego Supercomputer Center <*> "Oh my gosh! You are SO ahead of your time!" -- anon.