A method for suspending functions in C

Tim_N_Roberts at cup.portal.com Tim_N_Roberts at cup.portal.com
Wed Mar 7 05:26:06 AEST 1990


Someone who's name I've lost writes:

>     int onetoten()
>     {
>          static int state = 0;
>          static int i;
>
>          switch (state) {
>          case 0:
>               for (i = 1; i <= 10; i++) {
>                    state = 1;
>                    return i;
>          case 1:
>               }
>               state = 0;
>               return 0;
>          }
>     }

Mommy mommy, this man is scaring me.

I started shaking when I read this and I'm still shaking.  If I EVER find
code like this in a program I'm supposed to maintain, I intend to dial 911.

Can anyone convince me that this is guaranteed to work as designed?
 
TNR at cup.portal.com                |  "We come in peace. Set phasers to kill."
...!sun!portal!cup.portal.com!tnr |    - Star Trek Philosophy 101



More information about the Comp.lang.c mailing list