473,561 Members | 3,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Precedence of ?? (null coalescing) operator

The new ?? operator doesn't seem to be in the precedence table in
VS.05
<ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio .v80.en/dv_csref/html/214e7b83-1a41-4f7c-9867-64e9c0bab39f.ht m>,
and I can't seem to find anything about it online.

What's the precedence of the ?? operator?

[It doesn't seem like it would be "Primary" - up there with x.y, f(x),
a[x], x++, x--, new, typeof, checked, and unchecked - but it doesn't
seem "Unary", either. I hope there's not a new category between Unary
and Arithmetic!]

--
<http://www.midnightbea ch.com>
Jan 1 '06 #1
11 2527
Jon,

The ECMA Standard for C#
(http://www.ecma-international.org/pu...s/Ecma-334.htm, pag.
149) lists the null coalescing op ?? near the bottom of the precedence
table, above the ternary (conditional) and the assignment operators.

Regards,

Octavio
"Jon Shemitz" <jo*@midnightbe ach.com> escribió en el mensaje
news:43******** *******@midnigh tbeach.com...
The new ?? operator doesn't seem to be in the precedence table in
VS.05
<ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio .v80.en/dv_csref/html/214e7b83-1a41-4f7c-9867-64e9c0bab39f.ht m>,
and I can't seem to find anything about it online.

What's the precedence of the ?? operator?

[It doesn't seem like it would be "Primary" - up there with x.y, f(x),
a[x], x++, x--, new, typeof, checked, and unchecked - but it doesn't
seem "Unary", either. I hope there's not a new category between Unary
and Arithmetic!]

--
<http://www.midnightbea ch.com>

Jan 1 '06 #2
> The ECMA Standard for C#
(http://www.ecma-international.org/pu...s/Ecma-334.htm, pag.
149) lists the null coalescing op ?? near the bottom of the precedence
table, above the ternary (conditional) and the assignment operators.


Many thanks. Though knowing that there are now FIFTEEN levels of
precedence feels decidedly yucky. ;-)
The new ?? operator doesn't seem to be in the precedence table in
VS.05
<ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio .v80.en/dv_csref/html/214e7b83-1a41-4f7c-9867-64e9c0bab39f.ht m>,
and I can't seem to find anything about it online.

What's the precedence of the ?? operator?

[It doesn't seem like it would be "Primary" - up there with x.y, f(x),
a[x], x++, x--, new, typeof, checked, and unchecked - but it doesn't
seem "Unary", either. I hope there's not a new category between Unary
and Arithmetic!]


--
<http://www.midnightbea ch.com>
Jan 1 '06 #3
Jon,
Many thanks. Though knowing that there are now FIFTEEN levels of
precedence feels decidedly yucky. ;-)


Agreed. But anyway, operator precedence in C# seems to me a lot better
designed than in Pascal, right?

Regards,

Octavio
Jan 2 '06 #4
Octavio Hernandez wrote:
Many thanks. Though knowing that there are now FIFTEEN levels of
precedence feels decidedly yucky. ;-)


Agreed. But anyway, operator precedence in C# seems to me a lot better
designed than in Pascal, right?


Actually, Delphi has only four levels of precedence. That involves
silliness like calling bitwise `and` (C#'s & operator) a "multiplier ",
but four is better than fifteen, imho.

Though, I do find that C# precedence rarely gets in the way. It
usually does the right thing, without a lot of parens. I'm a bit
dubious about `(Type)(Expr)` code, where you have to parenthesize the
whole expression because casting has such high precedence, but I don't
find that this is all that common an issue.

--
<http://www.midnightbea ch.com>
Jan 2 '06 #5
Jon,
Though, I do find that C# precedence rarely gets in the way. It
usually does the right thing, without a lot of parens.


That's exactly what I was thinking about, I find annoying the need for a lot
of parens in Delphi whenever 'and' and 'or' are involved in an expression...

Best regards from a sure buyer of your book,

Octavio Hernandez
Madrid, Spain


Jan 3 '06 #6
Octavio Hernandez wrote:
Best regards from a sure buyer of your book,


Thanks. It's moving along nicely, after a long pause while my shoulder
ligaments grew back after a bike accident. Doing 2nd draft now -
checking against RTM bits, responding to tech reviewer comments, &c.

--
<http://www.midnightbea ch.com>
Jan 3 '06 #7
"Octavio Hernandez" <oc************ *****@gmail.com > wrote in message
news:uF******** ******@TK2MSFTN GP12.phx.gbl...
I find annoying the need for a lot of parens in


I have the exact opposite view. I generally code as if there are only
two levels:
* and / come before + and -
Everything else is determined by the parens.(*)

(*) OK, I don't really follow this literally -- e.g. I won't wrap a
obj.member in parens so that the dot-operator is handled first, but further
down the chart -- where the order gets murky, it often better to add a few
"unnecessar y parens" rather then count on both the original programmer & the
maintence programmer agree with the standard on the order.

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Jan 3 '06 #8
James,
it often better to add a few "unnecessar y parens"...


I understand your point of view, too. I guess the fact that generally
maintain my own code obviously has some influence on my opinion.

Regards - Octavio
Jan 3 '06 #9
Octavio Hernandez <oc************ *****@gmail.com > wrote:
it often better to add a few "unnecessar y parens"...


I understand your point of view, too. I guess the fact that generally
maintain my own code obviously has some influence on my opinion.


Out of interest - how often do you need to maintain code you wrote over
a year ago? I usually find that code I wrote but haven't looked at for
over a year is as "foreign" to me as code written by others. Maybe
that's just me though. It does mean I try to make things as readable as
possible though :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2377
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: An expression a = b() + c() * d++; can be transformed with the rules of operator associativity and operator precedence into a tree
4
3205
by: Master of C++ | last post by:
Hi, This is a simple question. In the following example, .. class Vector .. { .. private: .. int *Numbers; .. int vLength; ..
20
8130
by: Vivek N | last post by:
Hi Folks, This question may well have been asked and answered before. But, sorry that I couldn't find one from the archives. I typed up this program and compiled it with gcc 3.3.2 main() { int i = -3,j= 2,k=0,m; m = ++i || ++j && ++k; printf("\n%d %d %d %d\n",i,j,k,m);
21
3007
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as opposed to what is mentioned in precedence table? Also, with comma operator. consider,
11
1534
by: Rupesh | last post by:
Hello all, See the code .... int i=-3,j=2,k=0,m; m=++i;&&++j||++k; printf ("%d %d %d %d",i,j,k,m); I executed this code on gcc. the o/p i had got is:- -2 3 0 1
9
1994
by: Rich | last post by:
Hi I do like C# 2's new ?? operator, which enables us to code something like: // Ensure someString is not null someString = someString ?? ""; But wouldn't it make a lot of sense to take this a step further and allow a shorthand-assignment equivalent (much like +=, -= and so on)? I.e instead of what we have above, we could just say:
5
2528
by: junky_fellow | last post by:
Hi, I have a very basic doubt about associativity and precedence of operators. I am not a computer science person and may find it quite weird. Consider an expression 4+5*2
9
3733
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T'); printf("%d", a); /* code end */ 2
4
7187
by: shapper | last post by:
Hello, I have the following: DateTime c = database.Posts.Max(b =b.CreatedAt).Value; b.CreatedAt is of type "DateTime?" The problem is when database.Posts is empty. I get an error: Nullable object must have a value.
0
7639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8074
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5465
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5181
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3613
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3594
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.