comp.lang.ada
 help / color / mirror / Atom feed
From: David Thompson <dave.thompson2@verizon.net>
Subject: Re: Type convertion
Date: Mon, 24 Mar 2008 02:14:25 GMT
Date: 2008-03-24T02:14:25+00:00	[thread overview]
Message-ID: <sd1eu39s92mhhlh10mnr9k9rvhh6op8l78@4ax.com> (raw)
In-Reply-To: 22a25d83-4516-4f66-85b6-0382f2c951f5@b64g2000hsa.googlegroups.com

On Thu, 13 Mar 2008 01:33:46 -0700 (PDT), Maciej Sobczak
<see.my.homepage@gmail.com> wrote:

> On 12 Mar, 21:45, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> 
> > Yes.  My C is getting rustier by the day but I seem to remember that
> > the language standard does require enums to have the same size as int.
> 
To be pedantic, it's the 'width' (number of value bits) that matters,
not the size. C allows any integer type's representation to have
padding bits, so two types might have the same memory size but
different ranges, or even different sizes but the same range. Sane
implementors use this freedom only when necessary.

> No. The underlying type for enum has to be big enough to fit all
> defined values. It can be equivalent to int even for small sets, but
> does not have to be - in other words, it does not have to be bigger
> than necessary.
> 
For the enum _type_, right. As a convenient example, gcc has an option
-fshort-enums which does this. (To a first approximation, for all X
gcc has an option for X.) But the enum _constants_ are exactly 'int',
and (thus) must be in the range of int. (Yes, this is ugly.)

> And it can be larger that int for enums that don't fit in int.

Not in C. In _C++_ enum types can have values that exceed int but fit
in long, and the 'implementing' type can thus be anything up to long.
(When C++ adds C99's long long >=64b, I expect this will extend.)
And in C++ enum constants do have the 'correct' (enum) type.

- formerly david.thompson1 || achar(64) || worldnet.att.net



  reply	other threads:[~2008-03-24  2:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-11 16:10 Type convertion news.broadpark.no
2008-03-11 16:59 ` Ed Falis
2008-03-11 20:45   ` Ludovic Brenta
2008-03-12 20:36     ` Simon Wright
2008-03-12 20:45       ` Ludovic Brenta
2008-03-13  8:33         ` Maciej Sobczak
2008-03-24  2:14           ` David Thompson [this message]
2008-03-11 17:39 ` Jeffrey R. Carter
2008-03-11 20:53   ` news.broadpark.no
2008-03-11 21:40     ` Ludovic Brenta
2008-03-11 17:49 ` Stuart
2008-03-11 20:56   ` news.broadpark.no
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox