operator-precedence

Operator precedence for “<<” and “++” in VS2008 with optimization

為{幸葍}努か 提交于 2019-12-05 21:03:48
问题 I'm stuck with a weird VS2008 C++ issue, that looks like operator precedence is not respected. My question is what is the output of this: int i = 0; std::cout << ((i != 0) ? "Not zero " : "zero ") << ++i << std::endl; Normally the ++ has precedence over the << , right? Or is the << considered like a function call giving it a higher precedence than the ++ ? What is the 100% correct standard answer to this? To check, I created a new empty project (VS2008 console app), pasted only this code in

JavaScript evaluation order when assigning

て烟熏妆下的殇ゞ 提交于 2019-12-05 18:29:43
At what point does JavaScript determine the left-hand side of an assignment — is it before or after the right-hand side is evaluated? For example, what does this code do? var arr = [{thing:1},{thing:2},{thing:3},{last:true}]; arr[arr.length - 1].newField = arr.pop(); The left-hand side of an assignment operator is evaluated first. The specification for this as of ES2015 can be found in the "Runtime Semantics: Evaluation" portion of the "Assignment Operators" section and can be very roughly summarized as: Evaluate the LHS to determine the reference Evaluate the RHS to determine the value Assign

Call by value in the lambda calculus

ぐ巨炮叔叔 提交于 2019-12-05 13:05:44
问题 I'm working my way through Types and Programming Languages, and Pierce, for the call by value reduction strategy, gives the example of the term id (id (λz. id z)) . The inner redex id (λz. id z) is reduced to λz. id z first, giving id (λz. id z) as the result of the first reduction, before the outer redex is reduced to the normal form λz. id z . But call by value order is defined as 'only outermost redexes are reduced', and 'a redex is reduced only when its right-hand side has already been

The order of operators in JavaScript (|| ,&&)

安稳与你 提交于 2019-12-05 12:02:54
I am reading the source code of Underscore.js, then something confused me: // Its code, check the passed-in parameter obj _.isObject = function(obj) { var type = typeof obj; return type === 'function' || type === 'object' && !!obj; }; I am confused about the operator order of expression. I think the operator precedence in return type === 'function' || type === 'object' && !!obj; will be from left to right ; I mean equal to : return (type === 'function' ) || ( type === 'object' && !!obj); if type equal function return true ; else operate type === 'object' && !!obj ; if type equal object return

C# increment ToString

邮差的信 提交于 2019-12-05 10:44:08
I add an unexpected behaviour from C#/WPF private void ButtonUp_Click(object sender, RoutedEventArgs e) { int quant; if( int.TryParse(Qnt.Text, out quant)) { string s = ((quant++).ToString()); Qnt.Text = s; } } So, if I get quant as 1, quant will be incremented to 2. But the s string will be 1. Is this a question of precedence? EDIT: I re-wrote this as: quant++; Qnt.Text = quant.ToString(); and now this works as I expected. You are using the post -increment operator. This evalutates to the original value, and then increments. To do what you want in a one-liner you can use the pre -increment

Why are the 'dereference' and the 'address of' operators on the left?

吃可爱长大的小学妹 提交于 2019-12-05 09:19:25
In C (and some other C-like languages) we have 2 unary operators for working with pointers: the dereference operator ( * ) and the 'address of' operator ( & ). They are left unary operators, which introduces an uncertainty in order of operations, for example: *ptr->field or *arr[id] The order of operations is strictly defined by the standard, but from a human perspective, it is confusing. If the * operator was a right unary operator, the order would be obvious and wouldn't require extra parentheses: ptr*->field vs ptr->field* and arr*[id] vs arr[id]* So is there a good reason why are the

Shortcircuiting: OrElse combined with Or

微笑、不失礼 提交于 2019-12-05 08:40:39
If I have the following ... a OrElse b ... and a is True then clearly b is never evaluated. But if I add an Or , then what? a OrElse b Or c Does/should c get evaluated? And what if I put in some brackets? Apologies if this is basic. Of course I can test for the answer myself but I can't find this question answered here or elsewhere. Lots of questions dealing with Or versus OrElse but nothing dealing with Or with OrElse This is an operator precedence problem. The relevant documentation is here: http://msdn.microsoft.com/en-us/library/fw84t893.aspx?ppud=4 The important excerpts: Operators with

why does *p++ = *p - a give strange results?

两盒软妹~` 提交于 2019-12-05 08:19:05
While working with large arrays, I am doing unsafe pointer computations like the following: *c++ = *a++ - *b++; It works as expected. But for inplace operations, I need the c pointer on the right side as well: [STAThread] unsafe static void Main(string[] args) { double[] arr = new double[] { 2, 4, 6, 8, 10 }; double scalar = 1; fixed (double* arrP = arr) { double* end = arrP + arr.Length; double* p = arrP; double* p2 = arrP; while (p < end) { // gives: 3,5,7,9,2,4827634676971E+209 *p++ = *p - scalar; // gives correct result: 1,3,5,7,9 //*p = *p - scalar; //p++; } } Console.WriteLine(String

c# generic method overload not consistent with abstract Visitor pattern

我怕爱的太早我们不能终老 提交于 2019-12-05 07:33:52
experimenting with Visitor pattern and generic method I found a kind of discrepancy in C#.NET. AFAIK C# compiler prefers an explicit overload to a generic method, therefore the following code: public abstract class A { public abstract void Accept(Visitor v); } public class B : A { public override void Accept(Visitor v) { v.Visit(this); } } public class C : A { public override void Accept(Visitor v) { v.Visit(this); } } public class D : A { public override void Accept(Visitor v) { v.Visit(this); } } public class Visitor { public void Visit(B b) { Console.WriteLine("visiting B"); } public void

Mathematica: Evaluation order during numerical optimisation of black box functions

给你一囗甜甜゛ 提交于 2019-12-05 07:22:35
I am attempting to perform a numerical optimisation of a "black box" function in Mathematica. Schematically it goes like this: NMinimize[{comb[x,y,z], x > 0}, {x,y,z}] where comb[x,y,z] is defined similarly to this: comb[x_,y_,z_] := Module[{}, Print[x,y,z]; M = FindMaximum[SkewNormal[a,x,y,z], {a,x}] // First; val = f[x,y,z,M]; Return[val]; ]; However, all of the minimisation functions I have tried seem to not immediately provide comb[x,y,z] with numerical values, and it ends up trying to evaluate the FindMaximum with symbolic values for x,y,z (which is easily verified because the Print[x,y,z