Talk:Operators in C and C++: Difference between revisions

Content deleted Content added
m Reverted edits by 102.91.4.155 (talk) to last version by Afernand74
 
(12 intermediate revisions by 7 users not shown)
Line 1:
{{Talk header}}
{{WikiProject banner shell|class=C|1=
{{WikiProjectBannerShell|1=
{{WikiProject Computing |class=C |importance=Low}}
{{WikiProject C/C++|class=Start|importance=Top|c=yes|c++=yes}}
}}
Line 59:
 
: Agreed on separate articles. As a C programmer most of this is really hard to parse. [[Special:Contributions/174.21.162.147|174.21.162.147]] ([[User talk:174.21.162.147|talk]]) 02:47, 16 April 2015 (UTC)
:bc they are mostly the same. I cringe when folks cringe at lumping C and C++ together. We do it since it makes sense! but... (and as they say on GoT, you can ignore everything before but :)) why does this article exist? WP is not a programming manual! Delete this article. [[User:Stevebroshar|Stevebroshar]] ([[User talk:Stevebroshar|talk]]) 13:34, 30 January 2025 (UTC)
 
==order of operations==
Line 202 ⟶ 203:
 
:The keyword '''typeof''' is a non-standard extension to the C++ language. A similar feature will be provided by the '''decltype''' keyword in [[C++0x]]. The '''throw''' keyword is a standard part of the C++ language. That said, not all keywords are operators, and I am fairly certain that neither '''decltype''' nor '''throw''' would be considered to be operators. ← <span style="font-family: serif;"><b>[[User:Michael Safyan|Michael Safyan]]</b></span><sup>&nbsp;([[User talk:Michael Safyan|talk]])</sup> 02:17, 8 May 2008 (UTC)
::It's a bit confusing, but while [[decltype]] is not explicitly referred to as an operator in the WP, the term "<ttcode>decltype</ttcode> operator" is frequently used in the proposals. <span style="font-family:monospace, monospace;">[[User:Decltype|decltype]]</span> ([[User talk:Decltype|talk]]) 17:15, 16 September 2009 (UTC)
 
: "throw" behaves as any other operator, except that it returns void type. The conditional operator has a special case for one operand being a throw-expression, such that "false? 3 : throw xyz()" is an expression of type int that never completes evaluation. [[User:Potatoswatter|Potatoswatter]] ([[User talk:Potatoswatter|talk]]) 09:43, 15 June 2010 (UTC)
Line 220 ⟶ 221:
 
I see that once again "this" has been removed. Even if technically not an operator, I think it should be here somehow, because I think many will try to find it here. At least could we have a discussion about it instead of an edit war. [[User:SimonTrew|SimonTrew]] ([[User talk:SimonTrew|talk]]) 17:34, 27 February 2009 (UTC)
:Yes, I considered adding a comment on the talk page. But I felt that my edit comment would be enough to settle the issue: '''''removed "this" from the table, per [class.this]/1 of the standard'''''. <ttcode>this</ttcode> is not an operator, so I think it's just confusing to have it in a list of operators. Possibly a mention at the bottom of the article, but not in the actual table. Just my 5c. <span style="font-family:monospace, monospace;">[[User:Decltype|decltype]]</span> 19:06, 27 February 2009 (UTC)
 
::Yeah I was kinda thinking the same myself. But actually I am coming round to your opinion and wonder if it is justified at all in this article, it's not difficult to search for. I'm just quite a fan of making cross-references, I think that is part of what gives Wikipedia its value. [[User:SimonTrew|SimonTrew]] ([[User talk:SimonTrew|talk]]) 06:57, 28 February 2009 (UTC)
Line 294 ⟶ 295:
== Overload prototypes ==
 
There's no indication of what the type "R" means. [[User:OrangeDog|OrangeDog]] &nbsp;<small>([[User talk:OrangeDog|τ]] &nbsp; &nbsp;[[Special:Contributions/OrangeDog|ε]])</small> 10:33, 23 June 2010 (UTC)
 
== Compound literals missing ==
Line 321 ⟶ 322:
From [[Operators_in_C_and_C%2B%2B#Notes]]:
 
"* For example, <code>++x*3</code> is ambiguous without some precedence rule(s). The precedence table tells us that: <ttcode>x</ttcode> is 'bound' more tightly to <ttcode>++</ttcode> than to <ttcode>*</ttcode>, so that whatever <ttcode>++</ttcode> does (now or later—see below), it does it ONLY to <ttcode>x</ttcode> (and not to <code>x*3</code>); it is equivalent to (<code>++x</code>, <code>x*3</code>)."
 
<s>This looks like it is saying that <code>++x*3</code> is equivalent to <code>(++x, x*3)</code>. Which is incorrect: with the comma operator, the arguments can be evaluated in any order.</s>
Line 397 ⟶ 398:
 
:At first, this article only mentioned the alternative keyword representations (like <code>or</code>). So, for consistency, I added digraphs since they were added to the standards at the same time and for the same reason. However, adding digraphs but not trigraphs also seemed inconsistent since they can both be used to represent the operators. <code>a??(0??)</code> and <code>a<:0:></code> mean exactly the same thing despite the former being just <code>a[0]</code> after the preprocessor and the latter using alternartive tokens with the same meaning. To a programmer using them it's a distinction without a difference. In addition, <code>a or b</code> is implemented as a keyword in C++ and as a macro in C. So, I argue that there is precedent to adding preprocessor substitutions to the list. And lastly, as you correctly said, trigraphs can also appear outside operators. However, that's also true for the keywords since in e.g. the declaration <code>int and a = 0;</code> the <code>and</code> is not an operator. [[User:Nickps|Nickps]] ([[User talk:Nickps|talk]]) 09:25, 27 October 2023 (UTC)
::After noticing that I still missed some digraphs and trigraphs on the conversion operators i.e.<code>R<%a%></code> and <code>R??<a??></code> plus the ones with <code>auto</code>, I realised the whole thing is pointless and removed all alternative spellings. If anyone disagrees they are free to revert but I don't think it's worth it. My argument above still stands which is why I also removed the operator synonyms like <code>and</code>. [[User:Nickps|Nickps]] ([[User talk:Nickps|talk]]) 22:54, 8 May 2024 (UTC)
 
== Is <code>decltype</code> an operator? ==
Line 403 ⟶ 405:
 
So, the question is: Should <code>decltype</code> be added to the list of operators? My opinion is that it should, since it does basically the same thing as the typeof operators, so I will be adding it to the page for consistency, but feel free to revert if you can come up with a good counterargument. [[User:Nickps|Nickps]] ([[User talk:Nickps|talk]]) 18:07, 30 October 2023 (UTC)
 
== Is it 4 or 6? ==
 
WRT "...all four relational operators are automatically generated if operator<=> is defined": There are 6 relational operators other than <=>. Either the text should say six instead of four or should list the 4 that it refers to. [[User:Stevebroshar|Stevebroshar]] ([[User talk:Stevebroshar|talk]]) 13:22, 31 January 2025 (UTC)
 
== Is this a list operators? or everything one can say about operators? ==
 
Considering that this article is described as a list of operators, the section '''Expression evaluation order''' seems out of place. It used to be named '''operator precedence''', but I renamed it since it covers more than precedence. Maybe originally it was only about precedence and then someone added associativity which changed the section to be more general: covering evaluation order. Scope creep! Whatever. Regardless, this section does not seem to be covered as part of a list of operators. It should be removed from this article or the intro should say this is all about C/C++ operators; not a list of operators. [[User:Stevebroshar|Stevebroshar]] ([[User talk:Stevebroshar|talk]]) 15:16, 31 January 2025 (UTC)