Re:Dennis Ritchie’s first C compiler (c. 1972)
by pjmlp on Friday March 12, 2021 @06:50PM
(#26442401)
Some would say,
https://multicians.org/history.html
Instead we pile mitigations on top of mitigations, with hardware memory tagging being the last hope to fix it.
Re:Dennis Ritchie’s first C compiler (c. 1972)
by colejohnson66 on Thursday March 11, 2021 @05:59PM
(#26430106)
Is there an explanation on why C’s operator precedence is weird? Such as: why does the bitwise AND have higher precedence than logical AND?
Re:Dennis Ritchie’s first C compiler (c. 1972)
by compiler-guy on Friday March 12, 2021 @05:41PM
(#26441847)
There is, and it is amusing
“In retrospect it would have been better to go ahead and change the precedence of & to higher than ==, but it seemed safer just to split & and && without moving & past an existing operator. (After all, we had several hundred kilobytes of source code, and maybe 3 installations....)“
Re:Dennis Ritchie’s first C compiler (c. 1972)
by briantakita on Friday March 12, 2021 @03:27PM
(#26440481)
> why does the bitwise AND have higher precedence than logical AND?
Why is this precedence weird? Bitwise AND tends to be used to transform data while a logical AND tends to be used for control flow.
Re:Dennis Ritchie’s first C compiler (c. 1972)
by colejohnson66 on Friday March 12, 2021 @03:42PM
(#26440634)
I meant equals having a higher precedence than bitwise AND.
As in:
if (x & 2 == 2)
...is actually parsed as: if (x & (2 == 2))
...which isn’t intuitive.
Re:Dennis Ritchie’s first C compiler (c. 1972)
by compiler-guy on Friday March 12, 2021 @05:42PM
(#26441853)
See the above example from dmr himself
If they had gone for wart-free on properly powered hardware, they would be stuck back in Multics land or living with the gnu Hurd—cancelled for being over budget or moving so slowly that projects that actually accomplish what the users need overtake them.
Do I wish that C had fixed its operator precedence problem? Sure. But the trade offs as a total package make a lot of sense.