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,a9b0810d3106d9b8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: David Thompson Newsgroups: comp.lang.ada Subject: Re: Fun with C Date: Thu, 05 May 2011 04:39:06 -0400 Organization: Poor Message-ID: References: <4daca6ba$0$6773$9b4e6d93@newsspool3.arcor-online.net> <33973ba6-c390-4af1-9116-6facb12e2878@u12g2000vbf.googlegroups.com> <4dad9c1b$0$6875$9b4e6d93@newsspool2.arcor-online.net> <0ee0dce3-9121-4af2-9c54-cd15264969ff@t19g2000prd.googlegroups.com> <4db07e47$0$6771$9b4e6d93@newsspool3.arcor-online.net> <4db085b6$0$26801$882e7ee2@usenet-news.net> <4db96f08$0$12042$882e7ee2@usenet-news.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx01.eternal-september.org; posting-host="Gnu3Xq836+gTmlL7My5jNg"; logging-data="16222"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YgTte2nGn5AzMvtjxvLlohaC4S6JmGgo=" X-Newsreader: Forte Agent 3.3/32.846 Cancel-Lock: sha1:gk0SgQhrZSfruCaPLaPB5pPlzBQ= Xref: g2news2.google.com comp.lang.ada:20138 Date: 2011-05-05T04:39:06-04:00 List-Id: On Thu, 28 Apr 2011 09:41:57 -0400, Hyman Rosen wrote: > On 4/28/2011 1:13 AM, David Thompson wrote: > > On Thu, 21 Apr 2011 15:27:40 -0400, Hyman Rosen > > wrote: > >> That doesn't work for C because a variable of an enum type > >> may hold any integer value up to the number of bits taken > >> by the largest enumerator (with a variation for negatives > >> that isn't important here). The C enum concept is meant to > >> encompass literals used as bit masks as well as singular > >> values. > > > > s/up to/up to at least/ > > C++ restricts the permitted values, as per 7.2/6: C++ kinda does; C doesn't. C++ makes each enum type a distinct type _implemented_ as some 'underlying' integral type with the additional constraint you quoted, plus restriction on conversion, and ability to overload. Trying to convert a value outside that range is 'unspecified' which means an implementation can use whatever it wants, and needn't document or diagnose; every C++ implementation I've seen just uses the out-of-range value up to the range of the underlying type, which gives the same effect as C although not officially guaranteed. C makes an enum type _be_ an integer type, with all the properties including value range of that type. To be exact it says 'compatible', and some other places in C 'compatible' is weaker than identity, but for enum there I see no detectable difference. A C99 implementation can have extended integer types, which could cover all bit widths, but usually it provides, and uses for enums, only a few. In fact in C it is easy and common for the compiler to just use type 'int' for all enum types. (In C enums can't exceed int, so this is always safe, though not always optimal; in C++ they can, but the underlying type can exceed int only if necessary. Of course on many machines nowadays int and long are the same size anyway, and C++1X with long long hasn't been approved yet last I looked.)