home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,504 of 4,675   
   Rod Pemberton to Bart   
   Re: Fast Fizz Buzz program   
   22 Jul 18 21:32:37   
   
   From: invalid@nospicedham.lkntrgzxc.com   
      
   On Sun, 22 Jul 2018 13:48:31 +0100   
   Bart  wrote:   
      
   > On 22/07/2018 12:56, Rick wrote:   
   > > On Saturday, July 21, 2018 at 7:27:49 PM UTC-4, Bart wrote:   
      
   > >> Is it that simple? The first error in your code was that 'num' was   
   > >> not defined. So I moved that further up.   
   > >   
   > > I only see one error in the code posted in this thread.  I   
   > > forgot to remove the "int num" parameter from other().  It   
   > > should've been void.   
   > >   
   >   
   >  >      void other(void)        { printf("%d\n", num);   }   
   >  >   
   >  >      void (*funcs[4])(int) = { other, fizz, buzz, fizzbuzz };   
   >  >   
   >  >      int num;   
   >  >   
   >   
   > Problem 1: the body of other() uses 'num', which is not defined until   
   > later.   
   >   
   > Problem 2; funcs[4] is declared as function pointers taking an int,   
   > although it is initialised to functions which take no arguments, and   
   > the pointers are called with no arguments.   
   >   
   > Now you mention an 'int num' parameter, which I can't see in your   
   > code, so a potential Problem 3.   
   >   
   > It is anyway not a simple typo that anyone can see at a glance. More   
   > importantly, if code hasn't been run, then we don't know if it's   
   > going to work, especially after ad hoc modifications by someone else   
   > who doesn't know what you had in mind.   
   >   
   > That's why I went with Ben's version just to get a ball-park   
   > performance figure for a C version of the algorithm.   
   >   
      
   Ok, I'm not sure why he didn't post corrections yet.  I'm tired of   
   reading this part of the thread.  So, this is probably what he intended.   
      
   #include    
      
   void fizz(int num)         { printf("fizz\n");      }   
   void buzz(int num)         { printf("buzz\n");      }   
   void fizzbuzz(int num)     { printf("fizzbuzz\n");  }   
   void other(int num)        { printf("%d\n", num);   }   
      
   void (*funcs[4])(int) = { other, fizz, buzz, fizzbuzz };   
      
   int num;   
      
   int main(void)   
   {   
     int threes = 1 << 2, fives = 1 << 4;   
      
     for (num = 1; num <= 100; ++num) {   
       funcs[(threes & 1) + (2 * (fives & 1))](num);   
      
       threes = (threes >> 1) | ((threes & 1) << 2);   
       fives  = (fives  >> 1) | ((fives  & 1) << 4);   
     }   
      
   return(0);   
   }   
      
      
   Rod Pemberton   
   --   
   As long as the UK continues to work with the EU, Brexit won't happen.   
   The first pawn sacrifice: Gibraltar. Set Gibraltar free.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca