4 ms·
Gah. Nice idea, but the double-operator hack seems quite painful and error prone, especially with operators right in the middle of the precedence hierarchy. T
by JoshTriplett 12y ago
Gah. Nice idea, but the double-operator hack seems quite painful and error prone, especially with operators right in the middle of the precedence hierarchy.
This might be one of the few rare justifications for overloading the comma operator, for syntax similar to that of Haskell's backquote:
arbitrary+expr ,foo, arbitrary-expr
Then the ,foo, would get processed last, letting the expressions evaluate first, which matches the semantics of Haskell's infixing backquotes (lowest precedence by default).
Even then, though, that would get ugly in a hurry when mixed with function calls, requiring parentheses for sanity.
- MaulingMonkey 12y agooperator, is one of the operators defining a sequence point (e.g. guaranteeing the left side of the expression executes in whole before the right - others being &&, ||, and ?:.) Overloading the operator removes this sequence point. Too sketchy for my blood. Some prior art: http://www.gamedev.net/blog/2/entry-19599-bad-code-here/ http://www.gamedev.net/blog/2/entry-19599-bad-code-here/
- Sharlin 12y ago* is a better choice if you need something arithmetic-like, for instance vector3 a, b; float f = a *dot* b; vector3 c = a *cross* c;