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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab1d177a5a26577d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!k17g2000pre.googlegroups.com!not-for-mail From: Hyman Rosen Newsgroups: comp.lang.ada Subject: Re: What's wrong with C++? Date: Wed, 16 Feb 2011 12:07:02 -0800 (PST) Organization: http://groups.google.com Message-ID: <87d2371e-af91-4d6a-8d5b-3ddb972d84fd@k17g2000pre.googlegroups.com> References: <1ee1a434-4048-48f6-9f5e-d8126bebb808@r19g2000prm.googlegroups.com> <4D5C1824.3020509@obry.net> <21443638-5ec6-49d4-aafe-6fbc1e59daba@r19g2000prm.googlegroups.com> NNTP-Posting-Host: 204.253.252.20 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1297886822 26828 127.0.0.1 (16 Feb 2011 20:07:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 16 Feb 2011 20:07:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k17g2000pre.googlegroups.com; posting-host=204.253.252.20; posting-account=NhXkHQoAAADUfNLRQrjReWdGEn5uz9E_ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:18279 Date: 2011-02-16T12:07:02-08:00 List-Id: On 2/16/2011 2:36 PM, KK6GM wrote: > Will a C++ compiler will reject this? > > enum {Red, Green, Blue}; > int x = Red + Green; > > You might argue that this is a different issue, but I'm still curious. No, it will not, and it is a different issue. The particular issue here is that enumeration literals in C and C++ have automatic conversion to integer (but not the other way in C++). Also, enumerations in C were intended to represent bit masks as well as sets of values, so in both C and C++ a variable of enumeration type may correctly hold values that represent the bitwise-or of any number (including 0) of the literals. This is legal C++: struct DamageType { enum E { Fire = 1, Acid = 2, Lightning = 4, Poison = 8 }; }; DamageType::E what_my_dragon_can_do = DamageType::E( DamageType::Acid | DamageType::Poison ); DamageType::E what_your_wimp_can_do = DamageType::E( 0 ); A plausible case can be made that the original incorporation of enum into C should have distinguished between masks and sets, but that opportunity is long gone.