[m-dev.] for review: direct retry

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Oct 16 14:22:33 AEDT 2000


On 16-Oct-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> > > +	MR_EvalMethod		MR_sle_eval_method:8;
> > 
> > Standard ANSI/ISO C does not allow enum bitfields.
> 
> Ah. I could easily fix this, by making the field of type MR_int_least8_t and
> casting it where it is referenced

You don't actually need to use casts.  GNU C doesn't warn about
assigning char to enums that fit in char or vice versa.
(There are some C compilers that warn about conversions between
integer types of different sizes, but in the case where one of
the integer types is a enum type and the range of the enum fits
within the size of the integer type, I don't think it is reasonable
to issue a warning, and so if we do ever use a compiler which warns
about such assignments, I think it would be reasonable to just turn
such warnings off.)

For documentation purposes, rather than making the field be of type
MR_int_least8_t, I would suggest using a typedef for MR_int_least8_t,
with the typedef being declared at the same point where the enum is
declared.  You could name the int_least8_t typedef `MR_EvalMethod' and
leave the enum as just `enum MR_eval_method' or typedef'd to
`MR_EvalMethodEnum'.

> but I would prefer not to. It would not be
> too bad for this field, since it is used only once or twice, but I want to
> make type_ctor_rep another 8-bit enum field, and *that* is used in lots of
> places.
> 
> Is this likely to be a problem in practice?

Yes.  For example, lcc doesn't support enum bitfields.

> Does MSVC support enum bitfields?

I don't know off-hand.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list