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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,ab1d177a5a26577d X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news-out.readnews.com!postnews7.readnews.com!not-for-mail Date: Thu, 17 Feb 2011 16:03:58 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: What's wrong with C++? References: <1ee1a434-4048-48f6-9f5e-d8126bebb808@r19g2000prm.googlegroups.com> <4D5C1824.3020509@obry.net> <21443638-5ec6-49d4-aafe-6fbc1e59daba@r19g2000prm.googlegroups.com> <87d2371e-af91-4d6a-8d5b-3ddb972d84fd@k17g2000pre.googlegroups.com> <87zkpuze5e.fsf@ludovic-brenta.org> <4d5d791f$0$17330$882e7ee2@usenet-news.net> <87vd0izba1.fsf@ludovic-brenta.org> <4d5d8112$0$17330$882e7ee2@usenet-news.net> <87pqqqz8o6.fsf@ludovic-brenta.org> In-Reply-To: <87pqqqz8o6.fsf@ludovic-brenta.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4d5d8d41$0$17330$882e7ee2@usenet-news.net> NNTP-Posting-Host: b724704d.usenet-news.net X-Trace: DXC=cCDZFkY=;1E\U\LJTjZF:EQFZ3T]GPM]GmX0AG3X_jUOiEKWiPgeB1EVjKk:Lk^BNAcR12TN^Bg7N:KNd2lZeh5LKl On 2/17/2011 3:51 PM, Ludovic Brenta wrote: > Hyman Rosen writes: >> C and C++ enumerations don't have arithmetic. >> They do convert automatically to integers, but >> they don't automatically convert back. > > Actually they do in the example you provided: > > 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 ); > > In this example, the two enumeration values are automatically promoted > to integer (which has arithmetic) ORed, then the result is automatically > converted back to the type DamageType::E. How is that automatic? It is explicitly converted back through DamageType::E( expression ) > Except that the value of what_my_dragon_can_do is not one of the > values defined in the type. Once again, this is a design decision made by those who brought enumerations into C. The value an enumeration may take is not restricted to being one of the enumerators because the language wants to support using enumeration literals as bitmasks. You may not like it, but this use is correct C++.