Reputation: 101
#include <stack>
#include <functional>
int main()
{
std::stack<std::function<int()>> s;
s.push(main);
return s.top()();
}
I get the following diagnostic:
result: runtime error time: 0.04s memory: 39704 kB signal: 11 (SIGSEGV)
What's going on here?
Upvotes: 0
Views: 827
Reputation: 61910
Standard answer: N3485 § 3.6.1/3
The function main shall not be used within a program.
That's pretty self-explanatory.
Upvotes: 1
Reputation: 96241
First, you aren't allowed to call main
yourself. Secondly, it appears to be doing "what you'd expect" and making the call, so you're causing infinite recursion which uses up all your stack space and then overflows it.
Upvotes: 6