3 ms·
I don't see anything "beautiful" here, it works and is performant but seems pretty average in term of readability
by nsonha 4y ago
I don't see anything "beautiful" here, it works and is performant but seems pretty average in term of readability
- abudabi123 4y agoEmacs has a DSL with the regex power and potential to make the reading experience better than poking toothpicks in your eyeball; experience and familiarity with the syntax sees beauty where others fail to?
- dev_snd 4y agoI never understood why incrementing a pointer while doing another operation, such as a comparison, is considered good style in C, TBQH. I think the go example is much more readable.
- rswail 4y agoBecause 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_register_addressing_modes https://en.wikipedia.org/wiki/PDP-11_architecture#General_re...
- im3w1l 4y agox86 has cmps for doing comparison with postincrement / postdecrement.
- azinman2 4y agoDo 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?
- School-Cotton 4y agoYes, modern compilers should treat them the same.
- rswail 4y agoSure, 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.
- im3w1l 4y agoI wanted to point out that such instructions are in use to this day rather than being than being something from a long gone era.
- christophilus 4y agoOf the C code I’ve seen, this is quite nice. It’s decently commented, and very simple. I’d say it’s above average, but that may say more about the codebases I’ve seen than it does about this example.