groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [groff] Duff's Device lurking in refer.cpp


From: Steffen Nurpmeso
Subject: Re: [groff] Duff's Device lurking in refer.cpp
Date: Tue, 26 Jun 2018 23:04:28 +0200
User-agent: s-nail v14.9.10-138-gbb01f2b9-dirty

G. Branden Robinson wrote in <address@hidden
beast.net>:
 |I enjoyed this Easter egg; maybe you will too.

Why easter egg if i might ask?

 |src/preproc/refer/refer.cpp:
  ...
 |    while (opt != 0 && *opt != '\0') {
 |      switch (*opt) {
  ...
 |      case '-':
 |        if (opt[1] == '\0') {
 |          finished_options = 1;
 |          opt++;
 |          break;
 |}
 |        if (strcmp(opt,"-version")==0) {
 |      case 'v': // <-- a gibbon on the syntax tree

I often use this kind of code and am very thankful that C allows
this.  I would not exactly call it easter egg, if you would
program this in assembler it would look much more natural than
here with the brace groups.
But interesting that you call it Duff's device, i thought that
exactly refers to a do..while() loop within a switch!, as in

              uir     szloop = (_bufsize + 8-1) >> 3;

              // do an odd switch and then 8 bytes at a time with Duff's
              // device instead; saves CMP's and conditional branches.
              switch(_bufsize & (8-1)) {
              case 0:
              do {
                      _HASH(ret, *(buf++));
              case 7: _HASH(ret, *(buf++));
              case 6: _HASH(ret, *(buf++));
              case 5: _HASH(ret, *(buf++));
              case 4: _HASH(ret, *(buf++));
              case 3: _HASH(ret, *(buf++));
              case 2: _HASH(ret, *(buf++));
              case 1: _HASH(ret, *(buf++));

              } while(--szloop);
              }

 |          printf("GNU refer (groff) version %s\n", Version_string);
 ...


--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]