When I have a main() function that calls another function, i.e.,
...
void somef(int);
int main() {
int a {};
std::cin>>a;
somef(a)
return 0; // never returns. }
...
Moreover, if the function I call is something like this:
...
void somef(int a) {
main()
return; // to make the not-returning behaviour more clear.
}
...
Can I make the memory where the activation records stored overflow since the program gets stuck between main()
and somef(int)
functions without returning? I am currently writing a program that makes calls like this and it seems to work just for now. However, I wonder if my program crashes if I could somehow put too many inputs successively. To test this, I have tried the below code:
#include <iostream>
using namespace std;
int somef(int);
int main()
{
long long int a;
while (true) {
somef(a);
}
return 0;
}
int somef(int a)
{
long long int b;
main();
return 1; // never enters return.
}
I put long long int
s to, hopefully, take up more memory in the activation records. The result is that the program terminates without any errors after approximately half a second. However, I expected that the while(true)
condition makes the program crash somehow. Is this a some kind of crash? If so, does this mean that the program would also crash if I somehow took too many inputs in the first part of the code I have shared?
Thanks =)