Dave,
Your code is a nice demonstration of a general technique to convert
loops to (tail)recursive calls, by passing the loop variable and the
list of changed variables as parameters. It is a good test for the
optimization capabilities of the compiler: it should convert the code
back to iterative (loop) form. Otherwise, one should use something like
this:
typedef unsigned long long UI64;
UI64 fib(int const n)
{
int i; UI64 t, a = 0, b = 1;
for( i = 1; i < n && a <= b; ++i) {
t = b; b += a, a = t; }
return b < a ? 0 : b;
}
Your code and this one relies on the "wrap-around at overflow" behavior
of the compiler. I did not find it documented. Have I missed it? There
are compilers, which return the largest possible number at an overflow,
others return some special value. Is it safe to rely on this
wrap-around?
Laszlo Hars
_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel