constexpr unsigned long long factorial(unsigned long long n)
{
return n > 1 ? n * factorial(n - 1) : 1;
}
I have just learnt that if I call a constexpr
function using a value known at compile time, the compiler will just replace that function with his final result.
So why do I get a crash at runtime after compiling this call to my function?
std::cout << factorial(10000);
If it was evaluated at compile time, I would get an error just builing my project and it wouldn't even start...
What's wrong?