Questions tagged [operators]
For questions about operators in programming languages. Operators are built-in tokens that perform specific operations on their operands distinct from functions.
37 questions
17
votes
2
answers
4k
views
What is the origin of ++ and --?
In a lot of languages (eg Java, C++, etc), you can use ++ and -- as increment/decrement operators.
What was the origin of ...
34
votes
6
answers
6k
views
Why do most languages have a complete operator precedence?
I actually drafted most of this question before the relevant stack overflow question but it's still relevant.
C has a famously confusing operator precedence order. It is divided into 15 levels and ...
1
vote
2
answers
356
views
Decimal point as a binary operation [closed]
I wonder if anyone has tried implementing the decimal point as a binary operation a.b = $f(a, b) = a+b/10^{1+floor(log_{10} b)}$
That would simplify the PL design, and add new possibilities. For ...
13
votes
2
answers
980
views
What optimizations are possible with unsequenced operators?
In C, most binary operators do not specify which operand will be evaluated first:
...
21
votes
6
answers
5k
views
Why is array access not an infix operator?
The typical syntax for accessing an array (or list, map and similar data structures) at a specific index is a[i]. I believe C first introduced it as syntax sugar, ...
4
votes
2
answers
559
views
Can two infix operators have the same priority, but different associativity? If so, how would it be implemented in the parser?
I am interested, is it possible that, in some programming language, two infix operators have the same priority, but different associativity? If so, how is that implemented in the parser?
11
votes
4
answers
5k
views
How do you correctly compile the chained comparison operators like ones that exist in Python (`a < b < c`), if `b` might have side-effects?
The most obvious way of supporting chained comparisons operators, such as a < b < c, is to rewrite it as ...
2
votes
1
answer
719
views
How is the VHDL operator `<=`, which can be both right-associative (signal assignment) and left-associative (less-than-or-equal), parsed?
One of the most confusing things to me about VHDL is that the <= operator can mean both "less than or equal to" and it can be a signal assignment ...
10
votes
3
answers
2k
views
What should be the precedence of the bitwise operators relative to each others?
In C, the relative precedence of bitwise operators is as follows, from high to low precedence:
...
8
votes
6
answers
4k
views
Why do relational comparison operators never short-circuit?
I just thought about the possibility for the less-than and-greater than operators to short-circuit. That is, they can skip evaluating their second operand if the value of the second operand logically ...
47
votes
6
answers
15k
views
Why do programming languages use the asterisk * for multiplication?
Having had very little math(s) education I'm trying to bring myself up to speed for university, which currently involves teaching myself the times tables, where X ...
3
votes
4
answers
434
views
Common postfix representations of pointer/reference operations
In some C-based languages (including C/C++ themselves and Rust), taking pointers/references and dereferencing is done with prefix operators & and ...
13
votes
5
answers
1k
views
Prior art on pipelines of function calls
Say I have a loop that looks like this:
for i in range(1, 10) {
print(i)
}
Now I want to take the same sequence in reverse, and filter out even numbers. I might ...
19
votes
3
answers
4k
views
Why does MATLAB have left division/solve?
In MATLAB (and Octave), the \ (or mldivide) and \. operators are provided with the exact ...
18
votes
9
answers
6k
views
Why add an increment/decrement operator when compound assignments exist?
Many languages have compound assignment statements, for example +=. However, for the common task of adding or subtracting 1 from a variable some languages (mostly ...