by bee_rider · 3y ago · 0 comments
Consider
x = -5
now how about: x =- 5
One makes x negative 5, the other subtracts 5 from it. And under this design of the operator the only difference is a space.It's the same with +, just that we're not used to seeing unary plus in the wild.
I think you mean: x -= 5, which indeed is different.
Kind of how we use (*p)->next instead of *p->next where p is node_t**
Imagine if we had to watch out for this as a common pitfall:
// BUG! Actually subtracts x from current val of neg_x.
neg_x = -x;
Even moreso, how would these two lines behave? Would they differ in semantics? n = -5
n =- 5
Overall, -= is just so much less ambiguous.EDIT: To your point about ->, I personally think C would be better if:
*p->next
parsed as: (*p)->next
instead of: *(p->next)
but maybe now I'm not thinking through all the parsing impliciations :)So that is problematic; If {a}{=}{-}{b} means a = a - b, then you have no way to write a = -b without parentheses like a = (-b).