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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,74b958f114ec4924 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!cycny01.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc04.POSTED!7c706d3b!not-for-mail From: David Thompson Newsgroups: comp.lang.ada Subject: Re: Type convertion Organization: Poor Message-ID: References: <47d6ae9b$1@news.broadpark.no> <878x0pt2gg.fsf@ludovic-brenta.org> <87r6efsmc7.fsf@ludovic-brenta.org> <22a25d83-4516-4f66-85b6-0382f2c951f5@b64g2000hsa.googlegroups.com> X-Newsreader: Forte Agent 3.3/32.846 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 24 Mar 2008 02:14:25 GMT NNTP-Posting-Host: 70.18.191.26 X-Complaints-To: abuse@verizon.net X-Trace: trnddc04 1206324865 70.18.191.26 (Sun, 23 Mar 2008 22:14:25 EDT) NNTP-Posting-Date: Sun, 23 Mar 2008 22:14:25 EDT Xref: g2news1.google.com comp.lang.ada:20554 Date: 2008-03-24T02:14:25+00:00 List-Id: On Thu, 13 Mar 2008 01:33:46 -0700 (PDT), Maciej Sobczak wrote: > On 12 Mar, 21:45, Ludovic Brenta 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