Norman Vine wrote:
>
> Andy Ross writes:
> >
> > There's no way (short of user-space context
> > switching voodoo) to return to the top-level stack frame without
> > trashing the frame of the recursive call.
>
> there is some neat 'C' voodoo here
> http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
google('coroutine') returned this gem @
http://lambda.weblogs.com/discuss/msgReader$6981
#include <iostream>
#include <algorithm>
using namespace std;
class Coro {
public:
Coro() : st(0) { }
protected:
int st;
};
#define coreturn(x) do { \
this->st = __LINE__; return (x); case __LINE__: ; \
} while (0)
#define coro(x) class x : public Coro
#define coro_start(ret, args...) \
public: \
ret operator() (args) { \
switch (st) { \
case 0:
#define coro_end(x) default: return x; } }
coro(Perm) {
int i;
Perm *recur;
coro_start(char *, char *s);
if (!s[0]) {
coreturn(s);
} else {
for (i=0; s[i]; i++) {
recur = new Perm();
swap(s[0],s[i]);
while ((*recur)(s+1))
coreturn(s);
swap(s[0],s[i]);
delete recur;
}
}
coro_end(NULL);
};
int main(int argc, char ** argv)
{
char *s;
Perm permute;
if (argc != 2) {
cerr << "usage: " << argv[0] << " abc\n";
exit(1);
}
while (s = permute(argv[1])) {
cout << s << "\n";
}
exit(0);
}
_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel