R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

ちょっとしたクイズです(その2)

http://blogs.wankuma.com/rti/archive/2009/06/15/175382.aspx
ちょっとしたクイズです

回答編として

計算式をトレース

してみました。

間違ってないかドキドキです~


i *= ~i & 2 | 1 * (++i) - -(i--) ^ i; // 最初の状態
i *= -1 & 2 | 1 * (1) - -(1) ^ 2; // 基本式と単項式評価
i *= -1 & 2 | 1 * 1 - -1 ^ 2; // 括弧を展開
i *= -1 & 2 | 1 - -1 ^ 2;  // 乗算式を評価
i *= -1 & 2 | 2 ^ 2; // 減算式を評価
i *= 2 | 2 ^ 2; // AND 演算子を評価
i *= 2 | 0; // XOR 演算子を評価
i *= 2; // OR 演算子を評価
0; // 複合代入演算子を評価


最後の、複合代入演算子によって、後の演算結果に関係なくゼロが乗算の左辺になるので、最終的にゼロが i に代入されます。

投稿日時 : 2009年6月16日 13:44

Feedback

# re: ちょっとしたクイズです(その2) 2009/06/16 15:44 えムナウ

>赤字の部分だけ見て、ゼロだと判断した人は、ちょっと注意不足ですよ~
え~、なぜ?

>最後の、複合代入演算子によって、後の演算結果に関係なくゼロが乗算の左辺になるので、最終的にゼロが i に代入されます。
こう書いてあるじゃん。

# re: ちょっとしたクイズです(その2) 2009/06/16 15:44 れい

質問です。

> 最後の、複合代入演算子によって、後の演算結果に関係なくゼロが乗算の左辺になるので、最終的にゼロが i に代入されます。

「後の演算結果に関係なくゼロが乗算の左辺になる」のなら、

> 赤字の部分だけ見て、ゼロだと判断した人は、ちょっと注意不足ですよ~

なぜ注意不足なのでしょう?

的外れな質問かもしれませんが、ちょっとよく理解できなくて。

# [C#] 式のトレース 2009/06/16 15:48 雑記 - otherwise

ちょっとしたクイズです (R.Tanaka.Ichiro’s Blog) ちょっとしたクイズです(その2) (R.Tanaka.Ichiro’s Blog) MSIL でチェックしたところ、違う結果が出ました。。。 以下、 R さんのコメントで違った点。 右辺の「 1 * 」のところは最適化で消えてしまうみたいです 評価

# re: ちょっとしたクイズです(その2) 2009/06/16 16:26 R・田中一郎

えムナウ さん
れい さん

すみません。勘違いしてましたorz

# re: ちょっとしたクイズです(その2) 2009/06/16 20:26 出水

>i *= ~i & 2 | 1 * (++i) - -(i--) ^ i; // 最初の状態
>i *= -1 & 2 | 1 * (1) - -(0) ^ i; // 基本式と単項式評価

ここ間違ってますね~

# re: ちょっとしたクイズです(その2) 2009/06/17 5:14 R・田中一郎

どこがですか?

# re: ちょっとしたクイズです(その2) 2009/06/18 2:10 長月葵

> i *= 2 | 1; // XOR 演算子を評価
> i *= 2; // OR 演算子を評価
 C#では 00000010b | 00000001b は 00000010b になるのですか?( ∵)

# re: ちょっとしたクイズです(その2) 2009/06/18 9:27 R・田中一郎

なるわけないです orz
一応、最初からトレースしなおしたものと置き換えておきました。
そしたら、出水さんの指摘の間違いも気付きました orz

#軽くめまいが・・・w

# re: ちょっとしたクイズです(その2) 2009/06/19 14:26 とっちゃん

んー??
評価順が多分間違ってると思われ。。。
一番最初は
i *= ...

i = i * ...
にするところからじゃないと、計算できないと思うんだけど?

今のコンピュータは、複合演算を遅延評価できるほど賢くはないと思いますが。。。?

# re: ちょっとしたクイズです(その2) 2009/06/21 10:03 R・田中一郎

まー実際は、そうなんでしょうね。

上記の順であることを表記している理由が以下です。

http://msdn.microsoft.com/ja-jp/library/aa691323(VS.71).aspx
7.2.1 演算子の優先順位と結合規則

上記の表記によると、複合代入演算子の評価は最後になっています。

言語の演算優先規則と、MSIL の最適化やアセンブリレベルの実行演算順序は必ずしも同じではないと思います。

この場合、基本的には言語の演算優先規則に準じたものとした前提で理解していればOKだと思った訳ですよ。

# re: ちょっとしたクイズです(その2) 2009/06/24 1:15 ひょうが

//i *= ~i & 2 | 1 * (++i) - -(i--) ^ i; // 最初の状態
//i *= -1 & 2 | 1 * (1) - -(1) ^ 2; // 基本式と単項式評価

一番最後の^2って^0じゃない?自信ないけど。

#式は左から評価されるものと思ってました
#同じ優先度は右から(++i), (i--)の順なんですねー
#知りませんでした

# re: ちょっとしたクイズです(その2) 2009/06/24 1:16 ひょうが

誤記です。左右間違えました。
以下修正↓
#式は右から評価されるものと思ってました
#同じ優先度は左から(++i), (i--)の順なんですねー
#知りませんでした

# re: ちょっとしたクイズです(その2) 2009/06/24 15:12 R・田中一郎

>一番最後の^2って^0じゃない?自信ないけど。

あー、やっぱりそうなんかな?
最初の 0 の値が適用されるってことですよね。


# EPQQAYrYmdjoDx 2020/12/25 11:03 https://suba.me/

2sa17N Yeah bookmaking this wasn at a high risk decision outstanding post!.

# sWtEXSjxRHqSMP 2020/12/29 3:36 https://edukite.org/members/lampjumbo1/activity/83

There is obviously a lot to know about this. I think you made various good points in features also.

# XRETrTvUeahYZPlGg 2020/12/29 4:27 https://www.evernote.com/shard/s370/sh/946bc7b0-29

I value the post.Thanks Again. Really Great.

# FPQLxgYTkLCnUwKLMnm 2020/12/29 5:24 https://www.empaako.org/members/fenderice9/activit

Marvelous, what a weblog it is! This web site provides helpful information to us, keep it up.

# HTyVulqmdWymTsLd 2020/12/29 14:06 http://balkhashtur.kz/user/Geksodadots941/

my review here I want to create a blog that has a creative layout like what you find on MySpace, but with more traffic. I am not a fan of the Blogger site... Any suggestions?.

# XZvIAyypUjfaPkLc 2020/12/30 0:03 https://www.fpgacentral.com/group/members/frieryre

Yeah bookmaking this wasn at a bad decision great post!.

# fpejVQQNCbOFGc 2020/12/30 4:35 http://aikidoyukishudokan.com/forum/member.php?216

Loving the info on this website , you have done outstanding job on the blog posts.

# XZYuJbmPPMho 2020/12/30 7:04 https://www.fpgacentral.com/group/members/frieryre

thing to be aware of. I say to you, I certainly get

# ZoJZaSXfQaFpza 2020/12/30 23:43 https://apnews.com/article/online-media-social-med

Sweet blog! I found it while browsing on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I ave been trying for a while but I never seem to get there! Thanks

# oAXAiWpKffmYovJzv 2020/12/31 8:33 http://www.myeducationalshop.com/members/cloudysig

Muchos Gracias for your post.Really looking forward to read more. Fantastic.

# HsVMbyclqXjrXWLDYE 2020/12/31 13:12 http://what-the-fit.com/members/busflare9/activity

I visited a lot of website but I believe this one has got something extra in it. You can have brilliant ideas, but if you can at get them across, your ideas won at get you anywhere. by Lee Iacocca.

# MXoFzatXLzPX 2020/12/31 17:05 http://www.deportivo-la-coruna.com/forum/member.ph

Whoa! This blog looks just like my old one! It as on a totally different subject but

# rTwZIPWifPMJw 2021/01/01 1:47 https://apnews.com/press-release/newmediawire/tech

this topic to be really something that I think I would never understand.

# kYelKtrlYePNWyaP 2021/01/01 18:52 http://palz.one/index.php?title=User:Bobbye0069

Really informative post.Really looking forward to read more. Much obliged.

# avAnGPfobAbZkeolgh 2021/01/04 1:59 https://apnews.com/press-release/newmediawire/tech

You ave made some good points there. I looked on the web to learn more about the issue and found most people will go along with your views on this website.

# xgNmQZEGnGYYlbH 2021/01/04 8:47 https://bestiptvsubscription.io

Must tow line I concur! completely with what you said. Good stuff. Keep going, guys..

# BFTrHeJFVHW 2021/01/04 21:09 https://ks-barcode.com/receipt-printer/zebra/zq220

Wow, amazing blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is great, as well as the content!

# UhLjDSXkmOBpnfWotY 2021/01/05 13:34 https://grizzlyhalltexas.com/provider-gaming-profe

It'а?s actually a great and helpful piece of info. I'а?m glad that you shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

# PXAaMeUTpCRpEcljtp 2021/01/05 15:49 https://www.recessindy.com/raja-togel-situs-empat4

This web site really has all the information and facts I wanted concerning this subject and didn at know who to ask.

# DmkPuKmPgYyykwWlB 2021/01/05 22:45 https://thailandgemsfair.com/semua-togel-yang-dipa

It as a very easy on the eyes which makes it much more pleasant for me to come here and visit more

# roykDftexEDnXxAHP 2021/01/06 17:21 wDcxqRrxfmSEWRtf

pretty helpful stuff, overall I believe this is well worth a bookmark, thanks

# WgHWjccjFAY 2021/01/06 22:25 https://www.prixrenaudot.org/bermain-judi-joker123

In my country we don at get any of this kind of article. Need to search around the globe for such quality stuff. I congratulate your effort. Keep it up!

# cSrFFEqRMhRGStUexG 2021/01/06 23:56 https://maps.google.ws/url?q=http://www.starbets10

the blog loads super quick for me on Internet explorer.

# SKQtOviquRjkYOVYKKw 2021/01/07 1:59 https://www.afortiori-bilbao.com/update-bonus-deng

Im grateful for the blog article.Really looking forward to read more. Fantastic.

# CvSYjgpoTchnM 2021/01/07 7:21 https://penzu.com/public/84825440

Woh I enjoy your content, saved to fav!.

# rzLvDfMsmSSlbTPIjLX 2021/01/07 16:06 https://www.openlearning.com/u/muscleorgan17/blog/

This web site certainly has all the information I wanted concerning this subject and didn at know who to ask.

# pphXZRxpAKANBXgRt 2021/01/07 23:17 https://zk-fm.top/user/bainumnitrumn372/

Thanks for sharing, this is a fantastic blog.Really looking forward to read more. Fantastic.

# OPmRVnbBhLCYw 2021/01/08 1:41 http://adamtibbs.com/elgg2/blog/view/772238/sushi-

This blog is without a doubt awesome and besides factual. I have picked helluva helpful advices out of this blog. I ad love to come back again soon. Cheers!

# CHSbZzAXRsBBswWZz 2021/01/08 2:55 http://www.badrgate.com/vb/member.php?u=22697

please pay a visit to the sites we stick to, like this one, as it represents our picks in the web

# txRIpVdbMnCVpG 2021/01/08 6:09 https://carrerasupuli.com/2020/11/24/very-best-mot

magnificent issues altogether, you simply gained a new reader. What would you recommend about your put up that you simply made some days ago? Any certain?

# gPnPLiZxFiolat 2021/01/08 19:36 https://apnews.com/press-release/newmediawire/tech

pretty valuable stuff, overall I imagine this is worthy of a bookmark, thanks

# PkLQpaFnmQpDCceXs 2021/01/09 9:42 https://hostulum.com/high-speed-cloud-hosting/

It as not that I want to replicate your web page, but I really like the layout. Could you tell me which theme are you using? Or was it especially designed?

# vwmLZLTEDFBVCbIYga 2021/01/09 16:03 https://www.pedicure.com/members/karateseeder70/ac

It is really a great and helpful piece of info. I am glad that you shared this useful info with us. Please keep us informed like this. Thanks for sharing.

# jaLwpYYujeZiiZq 2021/01/10 1:52 https://www.redfin.com/CA/Los-Angeles/11723-Mayfie

Thanks a lot for the article.Much thanks again. Keep writing.

# LiiuXTAxFCyVqYOydT 2021/01/11 20:20 https://www.language-policy.org/taruhan-togel-di-s

Really informative post.Thanks Again. Really Great.

# fMUuXcNbHHhegT 2021/01/12 0:55 https://siatex.com/healthcare-apparel/custom-face-

Terrific work! This is the type of info that should be shared around the net. Shame on the search engines for not positioning this post higher! Come on over and visit my site. Thanks =)

# nqsWulAadjt 2021/01/12 3:12 https://www.idyasinc.com/wholesale/athletic-shorts

I think this is a real great blog.Really looking forward to read more. Will read on...

# sOpHQQHghZRfBp 2021/01/12 7:48 http://talktopaul.com/long-beach-real-estate

Well, I don at know if that as going to work for me, but definitely worked for you! Excellent post!

# iTUAoKXDJgrfeRAQe 2021/01/12 21:47 https://www.evernote.com/shard/s392/sh/683df2c1-44

you are going to a famous blogger if you are not already.

# ZeAjMeYAJCvdIFx 2021/01/12 23:41 http://www.nz-hotrod.com/vbulletin/member.php?5086

seeing very good gains. If you know of any please share.

# PIZGFdSUopSHMjBIX 2021/01/13 2:54 https://e2stats.com/

robe de cocktail pas cher i am in fact delighted to read this blog posts which includes lots of valuable facts, many thanks for providing these kinds of statistics.

# fTKnUoEEQRAtmvaq 2021/01/13 8:07 http://mc-mody.net/index/8-12367

It as hard to find knowledgeable people on this topic, however, you seem like you know what you are talking about! Thanks

# vjprYkeQHkVBlX 2021/01/13 23:38 https://hostulum.com/

Really appreciate you sharing this post.Much thanks again. Want more.

# gWSCOrKzqMtxsHSXWx 2021/01/15 5:01 http://jakarta.sangsanguniv.com/members/jawindex4/

standard parts you happen to be familiar with but might not know how to utilize properly, along with other unique offerings in the car that ensure it is more hard to.

# RSZmYMsPhFdYeEhBf 2021/01/15 5:56 https://www.forexfactory.com/gissellewhit

Looking forward to reading more. Great article.Really looking forward to read more. Really Great.

# cOjoTajZUv 2021/01/15 20:39 http://www.creativesbase.com/user/Mubssyday481

widgets I could add to my blog that automatically tweet my newest twitter updates.

# KrcuEArKopBLmfgvziO 2021/01/16 10:31 http://xxxextreme.org/user/luchfrurnelon280/

This is one awesome post.Thanks Again. Much obliged.

# tYYsDSqHIUOvy 2021/01/16 22:24 https://www.ted.com/profiles/25660184

Time period may be the a lot of special tool to, so might be the organic options. Internet looking is definitely simplest way to preserve moment.

# yCvmnojBDsS 2021/01/17 0:37 https://bit.ly/3oLIhfY

Whoa! This blog looks exactly like my old one! It as on a totally different topic but it has pretty much the same layout and design. Great choice of colors!

# MFoLfCfesHIMXO 2021/01/17 5:05 http://www.fiatforever.com/members/248067-HINKOWEW

omg! can at imagine how fast time pass, after August, ber months time already and Setempber is the first Christmas season in my place, I really love it!

# yCfgLzvLsdDp 2021/01/18 23:33 https://www.paimexco.com/bangladesh/boys-garment-m

That is a very good tip particularly to those new to the blogosphere. Short but very precise info Appreciate your sharing this one. A must read article!

# lwoqXPxEfARvbQ 2021/01/19 1:53 https://www.like24.pl/

you could have an amazing blog here! would you prefer to make some invite posts on my blog?

# zAJUiCGPzlAMlEfHS 2021/01/19 7:57 https://en.chinazi.wiki/wiki/User:BookerHiatt920

Thanks for sharing, this is a fantastic blog article. Really Great.

# yIlwliVQOnvhq 2021/01/20 9:25 https://sites.google.com/view/xtrasize-pills/

We stumbled over here by a different website and thought I might as well check things out.

タイトル  
名前  
Url
コメント