Re: generator functions in another language
- From: "Gabriel Genellina" <gagsl-py2@xxxxxxxxxxxx>
- Date: Mon, 05 May 2008 02:28:30 -0300
En Mon, 05 May 2008 00:09:02 -0300, hdante <hdante@xxxxxxxxx> escribió:
Isn't this guy a bot ? :-) It's learning fast. I believe there is a
"frame" in C, composed of its stack and globals. For generators in C,
you may look for "coroutines". For example, see:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
A sample code follows:
#define crBegin static int state=0; switch(state) { case 0:
#define crReturn(i,x) do { state=i; return x; case i:; } while (0)
#define crFinish }
int function(void) {
static int i;
crBegin;
for (i = 0; i < 10; i++)
crReturn(1, i);
crFinish;
}
The "suspended state" is saved in the static variable. It's not
necessary to save the complete "frame", only the suspended state.
Quoting the author himself, "this is the worst piece of C hackery ever seen"
--
Gabriel Genellina
.
- Follow-Ups:
- Re: generator functions in another language
- From: castironpi
- Re: generator functions in another language
- References:
- generator functions in another language
- From: castironpi
- Re: generator functions in another language
- From: Marc 'BlackJack' Rintsch
- Re: generator functions in another language
- From: Gabriel Genellina
- Re: generator functions in another language
- From: castironpi
- Re: generator functions in another language
- From: hdante
- generator functions in another language
- Prev by Date: Re: Truncate beginning of a file
- Next by Date: USB HID documentation?
- Previous by thread: Re: generator functions in another language
- Next by thread: Re: generator functions in another language
- Index(es):
Relevant Pages
|