From -1469744924624835749
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7538bd92d6a9557a
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1995-01-20 14:17:22 PST
Newsgroups: comp.std.c++
From: andys@thone.demon.co.uk (Andy Sawyer)
Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!gw1.att.com!fnnews.fnal.gov!mp.cs.niu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!pipex!peernews.demon.co.uk!thone.demon.co.uk!andys
Subject: Re: short enum, bool
References: <scottyD2DFML.MDt@netcom.com> <D2JJ3z.Cvw@ukpsshp1.serigate.philips.nl>
Organization: The United Federation Of Planets
Reply-To: andys@thone.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.29
Lines: 39
X-Posting-Host: thone.demon.co.uk
Date: Fri, 20 Jan 1995 22:17:22 +0000
Message-ID: <790640242snz@thone.demon.co.uk>
Sender: usenet@demon.co.uk

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

[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.

 I've wonder about this for a while, as it leads me to think that 
sizeof( enum ) may be meaningless. Since the compiler is, as you say, free
to choose the size of an enum, what happens in the following case:

 enum little { l_lo = 0, l_hi = 1   };  // Will fit in a single bit
 enum big    { b_lo = 0, b_hi = 256 };  // Needs at least 9 bits

 cout << ( ( sizeof( little ) == sizeof( big  )) ? "l==b" : "l!=b" ) << endl;
 cout << ( ( sizeof( little ) == sizeof( enum )) ? "l==e" : "l!=e" ) << endl;
 cout << ( ( sizeof( big    ) == sizeof( enum )) ? "b==e" : "b!=e" ) << endl;

 Even more curious would be the case of
 enum big_x   { big_x_lo = 1, big_x_hi = 256 };

 Would it be legal for a compiler to implement this as an 8 bit value,
applying a +/- 1 adjustment on conversions to/from the type? What about
a single bit? (Probably not the latter - but the former?)

 sizeof( big_x ) == ?;

Any takers?

Regards,
 Andy
-- 
* Andy Sawyer ** e-mail:andys@thone.demon.co.uk ** Compu$erve:100432,1713 **
 The opinions expressed above are my own, but you are granted the right to
 use and freely distribute them. I accept no responsibility for any injury,
 harm or damage arising from their use.                --   The Management.


