Hacker News new | ask | show | jobs
by rswail 1403 days ago
Because C was originally for PDP/DEC equipment and the instruction set had standard register access modes including both pre and post increment.

So the (for example) strcmp "while (s++ == d++);" made sense as efficient code, because the pointer access and the post increment effectively compiled down to almost a single instruction.

https://en.wikipedia.org/wiki/PDP-11_architecture#General_re...

1 comments

x86 has cmps for doing comparison with postincrement / postdecrement.
Sure, but the point was that C was designed to implement Unix and Unix was implemented on DEC machines and DEC machines had a particular architecture around registers that included the pre/post increment, which lead to the C *p++ style to iterate.
I wanted to point out that such instructions are in use to this day rather than being than being something from a long gone era.
Do compilers use that if you break it apart to something more legible? If you don’t, does the intel cpu end up doing the right thing anyway?
Yes, modern compilers should treat them the same.