From 3854316073351404394
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7538bd92d6a9557a
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1995-01-21 08:00:30 PST
Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!gw1.att.com!fnnews.fnal.gov!uwm.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!pipex!sunic!news.lth.se!nic.lth.se!dag
From: dag@control.lth.se (Dag Bruck)
Newsgroups: comp.std.c++
Subject: Re: short enum, bool
Date: 21 Jan 1995 16:00:30 GMT
Organization: Department of Automatic Control, Lund, Sweden
Lines: 39
Message-ID: <DAG.95Jan21170030@bellman.control.lth.se>
References: <scottyD2DFML.MDt@netcom.com> <D2JJ3z.Cvw@ukpsshp1.serigate.philips.nl>
	<790640242snz@thone.demon.co.uk>
NNTP-Posting-Host: control.lth.se
In-reply-to: andys@thone.demon.co.uk's message of Fri, 20 Jan 1995 22:17:22 +0000

>>>>> "A" == Andy Sawyer <andys@thone.demon.co.uk> writes:

A> In article <D2JJ3z.Cvw@ukpsshp1.serigate.philips.nl>
A> baynes@ukpsshp1.serigate.philips.nl "Stephen Baynes" writes:

A> [snip stuff about 'short enums']

>> Some C and C++ compilers do offer this as an extension. However for
>> space saving it is unecessary - just buy yourself a good compiler -
>> this will chose the size of an enum according to the range of the
>> enumeration values you specified for it.

A> Since the compiler is, as you
A> say, free to choose the size of an enum, what happens in the
A> following case:

The compiler is somewhat constrained by the rules of the C++ working
paper, so we can say a few things about your examples.

A> enum little { l_lo = 0, l_hi = 1 }; // Will fit in a single bit

An enum which is not a bitfield must be an addressable unit, so
sizeof(any enum type) >= 1.

A> enum big { b_lo = 0, b_hi = 256 }; // Needs at least 9 bits

so sizeof(big) >= 2.

A> enum big_x { big_x_lo = 1, big_x_hi = 256 };
A>
A> Would it be legal for a compiler to implement this as an 8 bit
A> value, applying a +/- 1 adjustment on conversions to/from the type?
A> What about a single bit? (Probably not the latter - but the
A> former?)

No neither is legal, so sizeof(big_x) >= 2.


					-- Dag Bruck


