R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

三項演算子は上から評価される(その2)

http://blogs.wankuma.com/rti/archive/2008/09/02/155189.aspx
三項演算子は上から評価される

・・・の続きです。

皆さんの反応を見て

先頭の演算結果が優先される

と表現する方が正しいように思えてきました。


results = 式 ? 真の時の値 : 偽の時の値;


C# の三項演算子は、上記のように記述します。
多重で書く場合、次に続く三項演算子は「儀の時の値」を求めるための、言うなれば最初の三項演算子の一部であって同格ではない訳です。
同格ではない以上、() を記述して演算の順番を任意に変更することはできません。


results = 式 ? 真の時の値 : (式 ? 真の時の値 : 偽の時の値)


上記の()の処理は、偽の時の値を取得するための三項演算子なので、最初の式が真なら()内の演算結果を用いません。
仮に末尾の()内の演算が先に行われたとしても、この結果は変わりません。

と言うことで、前回の検証は、上記を検証するもので、評価処理順序を確認するものではないことがわかった訳です。

投稿日時 : 2008年9月3日 10:35

Feedback

# re: 三項演算子は上から評価される(その2) 2008/09/03 11:17 774RR

C/C++ の条件演算子 ?: は短絡評価です
C/C++ の言語仕様によると a ? b : c があるとき、
・a が評価され、かつ a の中の副作用が完了する
・a が真と評価されたら b だけが評価され c は評価されない
・a が偽と評価されたら c だけが評価され b は評価されない
C# の仕様として短絡評価が保証されていないのでしょうか?

> 仮に末尾の()内の演算が先に行われたとしても、この結果は変わりません。
() 内の評価が先に行われるととても困ります。
a==0 ? 0 : b/a と安全に書けなくなります。

# re: 三項演算子は上から評価される(その2) 2008/09/03 11:26 凪瀬

「短絡評価」に尽きますねぇ。
a == null ? "" : a.toString()
とかも短絡評価されることが前提だし。

# re: 三項演算子は上から評価される(その2) 2008/09/03 11:29 R・田中一郎

>・a が真と評価されたら b だけが評価され c は評価されない

ほほー、短絡評価と言うんですね。知りませんでした。

C# の仕様が短絡評価なのかどうかの情報ソースは知らないのですが、もう少しいじってネタに使用かなー、と思ってます^^;

>() 内の評価が先に行われるととても困ります。
>a==0 ? 0 : b/a と安全に書けなくなります。

ん?
どうしてでしょうか?

# re: 三項演算子は上から評価される(その2) 2008/09/03 11:31 R・田中一郎

そうかそうか、なるほど。
凪瀬さんの表記で短絡評価されないと困る理由が理解できました。

# re: 三項演算子は上から評価される(その2) 2008/09/03 11:34 R・田中一郎

あれ?
ひょっとして短絡評価ってショートサーキットのこと?^^;

#俺ってボケてる?

# re: 三項演算子は上から評価される(その2) 2008/09/03 12:50 凪瀬

あってますよ
http://ja.wikipedia.org/wiki/%E7%9F%AD%E7%B5%A1%E8%A9%95%E4%BE%A1

# re: 三項演算子は上から評価される(その2) 2008/09/03 17:12 れびん

蛇足ですが。
以前 FizzBuzz が話題になった時に、こんな記事を書きました。
 
http://d.hatena.ne.jp/levin_gsp/20071109/1194579778
 
(少なくとも)PHP 5.2.2 + Win では、ワンステップに三項演算子を3つ以上重ねると動作しません。
あり得ない。。。

# re: 三項演算子は上から評価される(その2) 2008/09/03 17:19 R・田中一郎

PHP 有り得ない
しかし、それよりも、かるあさんの人気に嫉妬w

# re: 三項演算子は上から評価される(その2) 2008/09/03 17:43 melt

>(少なくとも)PHP 5.2.2 + Win では、ワンステップに三項演算子を3つ以上重ねると動作しません。

これが原因かな?

http://d.hatena.ne.jp/uskz/20080903/p6

# re: 三項演算子は上から評価される(その2) 2008/09/03 19:07 れびん

>melt さん
おおお!
チェックしてみます♪

# re: 三項演算子は上から評価される(その2) 2008/09/03 21:44 れびん

>melt さん
Special Thanks です♪
おっしゃる通りでした。
解決編エントリ書いておきました。
 
http://d.hatena.ne.jp/levin_gsp/20080903/1220445755

# re: 三項演算子は上から評価される(その2) 2008/09/04 9:34 R・田中一郎

melt さん
れびん さん

>これが原因かな?
>
>http://d.hatena.ne.jp/uskz/20080903/p6

なるほど・・・^^;

# 三項演算子は上から評価される(その3) 2008/09/04 10:16 R.Tanaka.Ichiro's Blog

三項演算子は上から評価される(その3)

# 三項演算子は上から評価される(その3) 2008/09/04 13:24 R.Tanaka.Ichiro's Blog

三項演算子は上から評価される(その3)

# I read this post fully concerning the difference of most recent and earlier technologies, it's awesome article. 2018/10/05 4:00 I read this post fully concerning the difference o

I read this post fully concerning the difference of most recent and earlier technologies, it's awesome article.

# Wonderful post however , I was wondering if you could write a litte more on this topic? I'd be very grateful if you could elaborate a little bit further. Cheers! 2018/10/11 18:16 Wonderful post however , I was wondering if you co

Wonderful post however , I was wondering if you could write a litte more on this topic?
I'd be very grateful if you could elaborate a little bit further.
Cheers!

# Hi there! This article couldn't be written much better! Looking through this post reminds me of my previous roommate! He continually kept talking about this. I am going to forward this post to him. Fairly certain he will have a great read. Thanks for sha 2018/10/19 18:29 Hi there! This article couldn't be written much be

Hi there! This article couldn't be written much better!
Looking through this post reminds me of my previous roommate!
He continually kept talking about this. I am going to forward
this post to him. Fairly certain he will have a great read.

Thanks for sharing!

# It's awesome to pay a quick visit this website and reading the views of all colleagues on the topic of this post, while I am also eager of getting experience. 2018/11/04 23:09 It's awesome to pay a quick visit this website and

It's awesome to pay a quick visit this website and reading the
views of all colleagues on the topic of this post, while I am also eager of
getting experience.

# Hi there, I enjoy reading all of your article post. I like to write a little comment to support you. 2018/11/12 21:31 Hi there, I enjoy reading all of your article post

Hi there, I enjoy reading all of your article post. I like to write a
little comment to support you.

# Hello colleagues, its enormous piece of writing about cultureand fully defined, keep it up all the time. 2018/11/14 8:04 Hello colleagues, its enormous piece of writing ab

Hello colleagues, its enormous piece of writing about cultureand fully defined, keep it up all the time.

# I am really loving the theme/design of your weblog. Do you ever run into any web browser compatibility issues? A handful of my blog readers have complained about my website not operating correctly in Explorer but looks great in Firefox. Do you have any 2018/11/19 2:32 I am really loving the theme/design of your weblog

I am really loving the theme/design of your weblog.
Do you ever run into any web browser compatibility issues?
A handful of my blog readers have complained about my website not
operating correctly in Explorer but looks great in Firefox.
Do you have any advice to help fix this problem?

# My relatives always say that I am killing my time here at web, however I know I am getting experience every day by reading thes good articles. 2019/04/12 0:28 My relatives always say that I am killing my time

My relatives always say that I am killing my time here at web,
however I know I am getting experience every day by reading thes
good articles.

# Hmm is anyone else experiencing problems with the pictures on this blog loading? I'm trying to figure out if its a problem on my end or if it's the blog. Any responses would be greatly appreciated. 2019/04/25 19:26 Hmm is anyone else experiencing problems with the

Hmm is anyone else experiencing problems with the pictures
on this blog loading? I'm trying to figure out if its a problem on my end or if it's
the blog. Any responses would be greatly appreciated.

# You ought to take part in a contest for one of the finest websites on the internet. I'm going to highly recommend this site! 2019/06/10 19:18 You ought to take part in a contest for one of the

You ought to take part in a contest for one of the finest websites on the
internet. I'm going to highly recommend this site!

# I don't even know how I ended up here, but I thought this post was good. I don't know who you are but definitely you are going to a famous blogger if you aren't already ;) Cheers! 2019/07/17 9:46 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this
post was good. I don't know who you are but definitely you are going to a
famous blogger if you aren't already ;) Cheers!

# I don't even know how I ended up here, but I thought this post was good. I don't know who you are but definitely you are going to a famous blogger if you aren't already ;) Cheers! 2019/07/17 9:47 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this
post was good. I don't know who you are but definitely you are going to a
famous blogger if you aren't already ;) Cheers!

# I don't even know how I ended up here, but I thought this post was good. I don't know who you are but definitely you are going to a famous blogger if you aren't already ;) Cheers! 2019/07/17 9:48 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this
post was good. I don't know who you are but definitely you are going to a
famous blogger if you aren't already ;) Cheers!

# I don't even know how I ended up here, but I thought this post was good. I don't know who you are but definitely you are going to a famous blogger if you aren't already ;) Cheers! 2019/07/17 9:49 I don't even know how I ended up here, but I thoug

I don't even know how I ended up here, but I thought this
post was good. I don't know who you are but definitely you are going to a
famous blogger if you aren't already ;) Cheers!

# wibocPxyGqh 2021/07/03 1:33 https://www.pinterest.com/pin/788833690985485071

What Follows Is A Approach That as Also Enabling bag-gurus To Expand

# sBUrTCylAeIyFME 2021/07/03 3:02 https://amzn.to/365xyVY

Wow, great blog post.Really looking forward to read more. Much obliged.

# re: ??????????????(??2) 2021/07/18 2:43 hydroxychloroquine sulphate

what is chloroquine used for https://chloroquineorigin.com/# plaquenil sulfate 200 mg

# re: ??????????????(??2) 2021/07/27 13:04 hcqs side effects

chloroquine https://chloroquineorigin.com/# hydroxychloroquine sulfate tablets

# re: ??????????????(??2) 2021/08/09 6:44 define chloro

how does chloroquine work https://chloroquineorigin.com/# hydroxychloroquone

# When someone writes an article he/she retains the idea of a user in his/her mind that how a user can be aware of it. Therefore that's why this paragraph is amazing. Thanks! 2021/09/02 19:28 When someone writes an article he/she retains the

When someone writes an article he/she retains the idea of a user in his/her mind that how a user can be aware of it.
Therefore that's why this paragraph is amazing. Thanks!

# Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS. I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems? Anybody who knows the answer will you kindly respond? Thanx!! 2021/09/12 18:50 Oh my goodness! Awesome article dude! Thanks, Howe

Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS.
I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems?
Anybody who knows the answer will you kindly respond?
Thanx!! ps4 games https://bit.ly/3z5HwTp ps4

# Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS. I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems? Anybody who knows the answer will you kindly respond? Thanx!! 2021/09/12 18:51 Oh my goodness! Awesome article dude! Thanks, Howe

Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS.
I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems?
Anybody who knows the answer will you kindly respond?
Thanx!! ps4 games https://bit.ly/3z5HwTp ps4

# Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS. I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems? Anybody who knows the answer will you kindly respond? Thanx!! 2021/09/12 18:52 Oh my goodness! Awesome article dude! Thanks, Howe

Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS.
I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems?
Anybody who knows the answer will you kindly respond?
Thanx!! ps4 games https://bit.ly/3z5HwTp ps4

# Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS. I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems? Anybody who knows the answer will you kindly respond? Thanx!! 2021/09/12 18:53 Oh my goodness! Awesome article dude! Thanks, Howe

Oh my goodness! Awesome article dude! Thanks, However I am encountering problems with your RSS.
I don't know why I cannot subscribe to it. Is there anybody else having identical RSS problems?
Anybody who knows the answer will you kindly respond?
Thanx!! ps4 games https://bit.ly/3z5HwTp ps4

# I'm not sure why but this site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 17:02 I'm not sure why but this site is loading very slo

I'm not sure why but this site is loading very slow for me.
Is anyone else having this problem or is it a problem on my end?
I'll check back later and see if the problem still exists.
quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# I'm not sure why but this site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 17:03 I'm not sure why but this site is loading very slo

I'm not sure why but this site is loading very slow for me.
Is anyone else having this problem or is it a problem on my end?
I'll check back later and see if the problem still exists.
quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# I'm not sure why but this site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 17:04 I'm not sure why but this site is loading very slo

I'm not sure why but this site is loading very slow for me.
Is anyone else having this problem or is it a problem on my end?
I'll check back later and see if the problem still exists.
quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# I'm not sure why but this site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 17:05 I'm not sure why but this site is loading very slo

I'm not sure why but this site is loading very slow for me.
Is anyone else having this problem or is it a problem on my end?
I'll check back later and see if the problem still exists.
quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# What i don't understood is actually how you are now not actually a lot more neatly-liked than you might be now. You're so intelligent. You understand thus considerably with regards to this matter, made me individually believe it from so many numerous ang 2021/11/24 7:11 What i don't understood is actually how you are no

What i don't understood is actually how you are now not actually a lot more neatly-liked than you might be now.

You're so intelligent. You understand thus considerably with regards to
this matter, made me individually believe it from so many numerous angles.
Its like women and men are not involved unless it's one thing to do with Woman gaga!

Your personal stuffs outstanding. At all times take care of it up!

# This is a topic that is near to my heart... Many thanks! Where are your contact details though? 2021/12/26 0:29 This is a topic that is near to my heart... Many t

This is a topic that is near to my heart... Many thanks!

Where are your contact details though?

# fantastic points altogether, you simply received a new reader. What may you recommend about your submit that you just made some days in the past? Any certain? 2022/03/23 3:45 fantastic points altogether, you simply received a

fantastic points altogether, you simply received a new reader.

What may you recommend about your submit that you just made some days in the past?
Any certain?

# fantastic points altogether, you simply received a new reader. What may you recommend about your submit that you just made some days in the past? Any certain? 2022/03/23 3:46 fantastic points altogether, you simply received a

fantastic points altogether, you simply received a new reader.

What may you recommend about your submit that you just made some days in the past?
Any certain?

# fantastic points altogether, you simply received a new reader. What may you recommend about your submit that you just made some days in the past? Any certain? 2022/03/23 3:47 fantastic points altogether, you simply received a

fantastic points altogether, you simply received a new reader.

What may you recommend about your submit that you just made some days in the past?
Any certain?

# fantastic points altogether, you simply received a new reader. What may you recommend about your submit that you just made some days in the past? Any certain? 2022/03/23 3:48 fantastic points altogether, you simply received a

fantastic points altogether, you simply received a new reader.

What may you recommend about your submit that you just made some days in the past?
Any certain?

# I read this piece of writing fully regarding the difference of newest and preceding technologies, it's amazing article. 2022/03/23 17:43 I read this piece of writing fully regarding the d

I read this piece of writing fully regarding
the difference of newest and preceding technologies, it's amazing article.

# I read this piece of writing fully regarding the difference of newest and preceding technologies, it's amazing article. 2022/03/23 17:44 I read this piece of writing fully regarding the d

I read this piece of writing fully regarding
the difference of newest and preceding technologies, it's amazing article.

# I read this piece of writing fully regarding the difference of newest and preceding technologies, it's amazing article. 2022/03/23 17:45 I read this piece of writing fully regarding the d

I read this piece of writing fully regarding
the difference of newest and preceding technologies, it's amazing article.

# I read this piece of writing fully regarding the difference of newest and preceding technologies, it's amazing article. 2022/03/23 17:46 I read this piece of writing fully regarding the d

I read this piece of writing fully regarding
the difference of newest and preceding technologies, it's amazing article.

# I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an shakiness over that you wish be delivering the following. unwell unquestionably come further forme 2022/06/05 17:47 I loved as much as you'll receive carried out righ

I loved as much as you'll receive carried out right here.

The sketch is attractive, your authored material stylish. nonetheless, you
command get bought an shakiness over that you wish be delivering the following.
unwell unquestionably come further formerly again since exactly the same
nearly very often inside case you shield this increase.

# What's up to every body, it's my first visit of this blog; this webpage includes awesome and actually good stuff in favor of visitors. 2022/06/06 12:09 What's up to every body, it's my first visit of th

What's up to every body, it's my first visit of this blog; this webpage includes awesome and actually good stuff in favor of visitors.

# What's up to every body, it's my first visit of this blog; this webpage includes awesome and actually good stuff in favor of visitors. 2022/06/06 12:11 What's up to every body, it's my first visit of th

What's up to every body, it's my first visit of this blog; this webpage includes awesome and actually good stuff in favor of visitors.

# What's up to every body, it's my first visit of this blog; this webpage includes awesome and actually good stuff in favor of visitors. 2022/06/06 12:11 What's up to every body, it's my first visit of th

What's up to every body, it's my first visit of this blog; this webpage includes awesome and actually good stuff in favor of visitors.

# Just wish to say your article is as astonishing. The clearness in your submit is simply excellent and i could suppose you're an expert in this subject. Fine together with your permission allow me to snatch your feed to keep updated with imminent post. T 2022/06/10 23:57 Just wish to say your article is as astonishing. T

Just wish to say your article is as astonishing.

The clearness in your submit is simply excellent and i
could suppose you're an expert in this subject. Fine together with your permission allow me to snatch your feed to keep updated with imminent post.
Thanks one million and please carry on the rewarding work.

# I enjoy what you guys are up too. This kind of clever work and exposure! Keep up the amazing works guys I've added you guys to my personal blogroll. 2022/06/12 23:10 I enjoy what you guys are up too. This kind of cle

I enjoy what you guys are up too. This kind of clever work and exposure!
Keep up the amazing works guys I've added you guys to my personal blogroll.

# best erectile dysfunction pills https://erectionpills.best/
best ed drug 2022/06/28 11:09 ErectionPills

best erectile dysfunction pills https://erectionpills.best/
best ed drug

# I visited various sites except the audio quality for audio songs current at this site is truly excellent. 2022/07/07 12:02 I visited various sites except the audio quality f

I visited various sites except the audio quality for audio songs current at this
site is truly excellent.

# What's up i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment due to this sensible post. 2022/07/11 16:27 What's up i am kavin, its my first time to comment

What's up i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment
due to this sensible post.

# What's up i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment due to this sensible post. 2022/07/11 16:29 What's up i am kavin, its my first time to comment

What's up i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment
due to this sensible post.

# What's up i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment due to this sensible post. 2022/07/11 16:30 What's up i am kavin, its my first time to comment

What's up i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment
due to this sensible post.

# Just want to say your article is as astounding. The clearness to your publish is simply spectacular and that i can assume you're an expert on this subject. Fine with your permission let me to grab your feed to keep up to date with imminent post. Thanks 2022/07/22 12:42 Just want to say your article is as astounding. Th

Just want to say your article is as astounding. The clearness to
your publish is simply spectacular and that i can assume you're an expert
on this subject. Fine with your permission let me to grab your feed to keep up to date with imminent post.

Thanks 1,000,000 and please continue the gratifying work.

# Amazing! This blog looks just like my old one! It's on a entirely different subject but it has pretty much the same layout and design. Superb choice of colors! 2022/07/23 0:23 Amazing! This blog looks just like my old one! It'

Amazing! This blog looks just like my old one! It's on a entirely different subject but it has pretty
much the same layout and design. Superb choice of colors!

# Hi there, just wanted to tell you, I enjoyed this blog post. It was helpful. Keep on posting! 2022/08/04 3:20 Hi there, just wanted to tell you, I enjoyed this

Hi there, just wanted to tell you, I enjoyed this blog post.
It was helpful. Keep on posting!

# Hello just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Ie. I'm not sure if this is a formatting issue or something to do with browser compatibility but I figured I'd post to let you know. The layout 2022/08/09 3:00 Hello just wanted to give you a quick heads up. Th

Hello just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Ie.
I'm not sure if this is a formatting issue or something to
do with browser compatibility but I figured I'd post to let you know.
The layout look great though! Hope you get the problem
solved soon. Many thanks

# I am really delighted to glance at this website posts which carries plenty of helpful information, thanks for providing these information. 2022/08/12 0:58 I am really delighted to glance at this website po

I am really delighted to glance at this website
posts which carries plenty of helpful information, thanks for providing these information.

# I get pleasure from, cause I discovered just what I was taking a look for. You have ended my 4 day long hunt! God Bless you man. Have a great day. Bye 2022/08/13 15:22 I get pleasure from, cause I discovered just what

I get pleasure from, cause I discovered just what I was taking a look for.
You have ended my 4 day long hunt! God Bless you man.
Have a great day. Bye

# If you desire to improve your knowledge simply keep visiting this website and be updated with the latest gossip posted here. 2022/08/18 14:36 If you desire to improve your knowledge simply kee

If you desire to improve your knowledge simply keep visiting this website and be updated with the latest gossip posted here.

# paxlovid beipackzettel https://paxlovid.best/
paxlovid prix 2022/09/07 22:58 Paxlovid

paxlovid beipackzettel https://paxlovid.best/
paxlovid prix

タイトル
名前
Url
コメント