Useless use of goto

Someone showed me some beautiful code, that happens to be procmail’s. I’m really impressed :

goto jiasc; do { *++to= *++from; jiasc:; } while(--count);

I suggest anyone to take a look at procmail’s source code, it’s really a thrill.

2008-01-23 08:59:19+0900

miscellaneous, p.d.o

Both comments and pings are currently closed.

9 Responses to “Useless use of goto”

  1. housty Says:

    don’t understand this “goto” statement?

  2. Russ Says:

    I fail to see how it differs from:

    while (–count) { ++to = ++from; }

    Not to mention that the code does not do what one would expect with count of 1 (or worse, 0). Nor do I see the logic behind not using memcpy.

  3. bd_ Says:

    It’s equivalent to: while(–count) { ++to = ++from; }

    Which is the same as: to += 1; from += 1; memcpy(to, from, count); to += count – 1; // may be negative if count = 0 from += count – 1; count = 0;

    Why anyone would write such a thing is beyond me.

  4. bd_ Says:

    My mistake, the original code does nothing sane if count == 0. Add a count–; to the top of my code.

  5. Russ Says:

    and the to–; from–;

    With all the register keywords being thrown about, you’d think that the writer is attempting to achieve performance. A saner implementation is in lib/string.c in the kernel.

  6. ak Says:

    Yes, the procmail source code is really horrible… until a year ago or so, GNU indent crashed on it trying to indent it.

  7. Ben Hutchings Says:

    I looked at the procmail source code in about 1997 and shortly afterwards I stopped using it in disgust.

  8. Marius Gedminas Says:

    Speaking of beautiful code, I kind of like apt’s way of using booleans:

    if (match.filematch(f) == true && fixed[f->id] == false)

    Reminds me of first year computer science students.

  9. Zack Says:

    The last time I looked at the procmail source code (also about 1997) I came away with the impression that it had been mechanically translated from assembly language.