Posted on 2013-05-19 16:54
S.l.e!ep.¢% 阅读(1358)
评论(0) 编辑 收藏 引用 所属分类:
C++
好东西一定要分享, 分享而快乐..
#include <stdio.h>
#include <stdlib.h>
#define ccrContParam void **ccrParam
#define ccrBeginContext(x) struct ccrContextTag { int ccrLine
#define ccrEndContext(x) } *x = (struct ccrContextTag *)*ccrParam
#define ccrBegin(x) if(!x) {*ccrParam=malloc(sizeof(*x)); x= (struct ccrContextTag *)*ccrParam; x->ccrLine=0;}\
if (x) switch(x->ccrLine) { case 0:;
#define ccrFinish(z) } free(*ccrParam); *ccrParam=0; return (z)
#define ccrFinishV } free(*ccrParam); *ccrParam=0; return
#define ccrReturn(z) \
do {\
((struct ccrContextTag *)*ccrParam)->ccrLine=__LINE__;\
return (z); case __LINE__:;\
} while (0)
#define ccrReturnV \
do {\
((struct ccrContextTag *)*ccrParam)->ccrLine=__LINE__;\
return; case __LINE__:;\
} while (0)
#define ccrStop(z) do{ free(*ccrParam); *ccrParam=0; return (z); }while(0)
#define ccrStopV do{ free(*ccrParam); *ccrParam=0; return; }while(0)
#define ccrContext void *
#define ccrAbort(ctx) do { free (ctx); ctx = 0; } while (0)
int ascending(ccrContParam)
{
ccrBeginContext(foo);
int i;
ccrEndContext(foo);
ccrBegin(foo);
for (foo->i = 0; foo->i < 10; foo->i++)
{
ccrReturn(foo->i);
}
ccrFinish(-1);
}
void main(void)
{
ccrContext z = 0;
do
{
int res = ascending(&z);
if(z)
printf("got number %d\n", res);
} while (z);
}