c语言的cps实现求fibonacci数列示例
本文导语: CPS:http://en.wikipedia.org/wiki/Continuation-passing_style示例代码使用迭代 + 尾递归。 代码如下:#include typedef void (*END_OF_END)(unsigned long);void fibonacci(int, unsigned long, unsigned long, void(*)(unsigned long)); voidnotify(unsigned long res) { printf("Ultimate resu...
CPS:http://en.wikipedia.org/wiki/Continuation-passing_style
示例代码使用迭代 + 尾递归。
#include
typedef void (*END_OF_END)(unsigned long);
void fibonacci(int, unsigned long, unsigned long, void(*)(unsigned long));
void
notify(unsigned long res) {
printf("Ultimate result: %lun" res);
exit(0);
}
/* Note: Fibonacci number might overflow! */
void
fibonacci(int n, unsigned long v1, unsigned long v2, void(*notify)(unsigned long)) {
if (n