mildly obfuscating c

Frank Adams franka at mmintl.UUCP
Wed Dec 11 04:59:08 AEST 1985


In article <564 at puff.UUCP> tom at puff.UUCP writes:
>i haven't been able to figure out anyway to "goto" a label that
>i don't know.  for example, i would like to do this:
>
>-------------------------------------------------------------
>main() {
>	int (*jump[])() = { l1,l2,l3,l4,l5,l6,l7,l8 }
>
>	l1: /* code */
>	l2: /* code */
>	l3: /* code */
>	l4: /* code */
>	l5: /* code */
>	l6: /* code */
>	l7: /* code */
>	l8: /* code */
>
>	goto *jump[whatever]
>}
>-------------------------------------------------------------

First, why do you want to do this?  The correct way to write this code in
c is:

switch(whatever) {
   case 0: /* code */
   break;

   case 1: /* code */
   break;

   /* etc */
}

This covers 99.9% of all uses of computed GOTOs.  If you have one of the
rare applications it doesn't cover, put the GOTO's in the switch statement:

switch(whatever) {
   case 0: goto l1;

   /* etc */
}

Frank Adams                           ihpn4!philabs!pwa-b!mmintl!franka
Multimate International    52 Oakland Ave North    E. Hartford, CT 06108



More information about the Comp.lang.c mailing list