Re:What is your favorite C programming trick? (2009)
by abecedarius on Sunday November 22, 2020 @01:14PM
(#25179552)
It's too bad C's pointer-deref operator is prefix instead of postfix. In Pascal it's ^ so you write ptr^.member and there's no special -> operator. Even better, declarations and expressions would read intuitively left-to-right instead of spiraling out through stars on the left and brackets on the right.
[ Parent
| on HN ]
Re:What is your favorite C programming trick? (2009)
by btrask on Sunday November 22, 2020 @02:03PM
(#25180025)
In C you can use [0] for postfix pointer dereferencing.
Re:What is your favorite C programming trick? (2009)
by abecedarius on Sunday November 22, 2020 @04:03PM
(#25181079)
Alas, that's clumsy, and for declarations not possible. I have used it in expressions at times.
Here's a variation that seems plausible: make postfix p^ be like C's p[0], and infix p^i like C's p[i]. (With a tighter binding for ^ than C has.)
Re:What is your favorite C programming trick? (2009)
by Twisol on Sunday November 22, 2020 @03:42PM
(#25180871)
So that's where the lens notation comes from...
https://github.com/ekmett/lens/wiki/Examples
> ("hello","world")^._2