'goto" gone from computer languages or is it!

John Hogerhuis jhoger at gmail.com
Mon May 16 13:38:23 CDT 2005


The other one I use it for is jumping past the top of a loop the first
time only (this code probably doesn't work but you get the idea...):

#define DIM(a) (sizeof (a) / sizeof (*(a)))

int ary[4] = {1,3,5,7};
.
.
.
print_ary (ary, DIM (ary));

void print_ary (int *aryp, int n)
{

   goto skip_comma;
   for (;n;aryp++, n--)
      {
         printf (", ");

skip_comma:
          printf ("%u", *aryp);
      }
   printf ("\n");

}


State machines? If it is complex enough usually the better solution is
a two-way (current state, input) table of function pointers, unless
your implementation language doesn't support some analog to function
pointers...

-- John.



More information about the cctalk mailing list