From: jm@bourguet.org   
      
   George Neuner writes:   
      
   > On Wed, 11 Feb 2026 22:11:09 GMT, MitchAlsup   
   > wrote:   
   >   
   >   
   >>40 years ago, Duff's device was considered a reasonable way to improve   
   >>performance. It is now considered a means to take over applications   
   >>and machines (i.e., a virus).   
   >   
   > I don't know that it ever really improved performance, but it still is   
   > useful. I use the switch() form for backing out of situations having   
   > complicated setup where processing isn't possible unless all the setup   
   > steps succeed.   
   >   
   > I keep track of how many setup steps successfully complete, and then,   
   > whatever the exit situation, I jump into a Duff switch that tears it   
   > all down in reverse order of the setup.   
      
   This seems missing an important aspect of Duff switch: the use of the   
   possibility to put case labels inside control structure. Duff's device use   
   a while starting before the first label, but you can do other strange   
   things like jumping into an if:   
      
    switch(i) {   
    case 1:   
    if (j == 3) {   
    case 2:   
    printf("i == 2 || (i == 1 && j == 3)\n");   
    }   
    }   
      
   or is you tears down complex enough to use such things?   
      
   Yours,   
      
   --   
   Jean-Marc   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|