3 ms·
That behavior of "+" is defined in the standard, so you don't have to worry about which conforming compiler you are using. Adding integers to pointers can't be
by lurker19 15y ago
That behavior of "+" is defined in the standard, so you don't have to worry about which conforming compiler you are using. Adding integers to pointers can't be a syntax error, since otherwise arrays would be impossible. The commutativity of the bracket operator is a silly side effect of the commutativity of addition, but not broken in any way except maybe readability.
- lurker19 15y agoIt is also interesting to note that this behavior of '+' in C an C++ and Java is basically (logically) multiple-dispatch on the types of its arguments, but the language does not allow programmers to define operators like this -- C does not allow user-defined operators at all, in C++ you have to define the operator in every class that can appear on the left-hand-side, in Java you can define a method which looks almost like an operator but still has to be smeared across all classes (unless you write a utility class method Foo.plus(A, B) that eliminates the asymmetry between the two operands). This subordination of functions below objects, and special reservation of rights for builtins, is what functional programming language uses loath about non-FP languages.