order of evaluation of operands

In C++, for user-defined types a + b is a function call, and the standard says: §5.2.2.8 – […] The order of evaluation of function arguments is unspecified. […] For normal operators, the standard says: §5.4 – Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and … Read more

How to split a long regular expression into multiple lines in JavaScript?

Extending @KooiInc answer, you can avoid manually escaping every special character by using the source property of the RegExp object. Example: var urlRegex= new RegExp(” + /(?:(?:(https?|ftp):)?\/\/)/.source // protocol + /(?:([^:\n\r]+):([^@\n\r]+)@)?/.source // user:pass + /(?:(?:www\.)?([^\/\n\r]+))/.source // domain + /(\/[^?\n\r]+)?/.source // request + /(\?[^#\n\r]*)?/.source // query + /(#?[^\n\r]*)?/.source // anchor ); or if you want to … Read more

Assignment inside lambda expression in Python

The assignment expression operator := added in Python 3.8 supports assignment inside of lambda expressions. This operator can only appear within a parenthesized (…), bracketed […], or braced {…} expression for syntactic reasons. For example, we will be able to write the following: import sys say_hello = lambda: ( message := “Hello world”, sys.stdout.write(message + … Read more

Best and shortest way to evaluate mathematical expressions

Further to Thomas’s answer, it’s actually possible to access the (deprecated) JScript libraries directly from C#, which means you can use the equivalent of JScript’s eval function. using Microsoft.JScript; // needs a reference to Microsoft.JScript.dll using Microsoft.JScript.Vsa; // needs a reference to Microsoft.Vsa.dll // … string expr = “7 + (5 * 4)”; Console.WriteLine(JScriptEval(expr)); // … Read more

C comma operator

Section 6.6/3, “Constant expressions”, of the ISO C99 standard is the section you need. It states: Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated. In the C99 rationale document from ISO, there’s this little snippet: An integer constant expression … Read more