size_t fac(size_t n)
{
size_t res = n;
while (n--)
res *= n;
return res;
}
static assert(fac(3) == 6);
------
Comment #1 by clugdbug — 2011-11-18T13:07:40Z
That fails at run time, too. You're multiplying by zero!
Should be: while(--n)
(In reply to comment #0)
> size_t fac(size_t n)
> {
> size_t res = n;
> while (n--)
> res *= n;
> return res;
> }
>
> static assert(fac(3) == 6);
>
> ------