
Can someone tell me :roll:

int CalcMass(int x){ return CalcMass(x+1); }
/**
* Infraction is almighty.
* Infraction cannot be contained within a single object.
* If you attempt to do so, Infraction shall burst
* forth from its prison and destroy your world.
*/
public Infraction() {
new Infraction();
}
Szuwar wrote:So his avatar says that her weight is so huge that calculating it using such method would cause whole stack to be used and still not having any results (more or less).Correct me if I'm wrong, a stack overflow is when a stack is taking up way too much memory. For example:
int ovrflow() {
return ovrflow();
}
Sponge wrote:It's the call stack, specifically.Szuwar wrote:So his avatar says that her weight is so huge that calculating it using such method would cause whole stack to be used and still not having any results (more or less).Correct me if I'm wrong, a stack overflow is when a stack is taking up way too much memory. For example:Code: Select allThis will create an integer variable called "ovrflow". It's value is taken from the variable "ovrflow", which if you didn't notice, is itself. What will happen is that it will create ovrflow, then look to ovrflow for answers on what integer it should represent. ovrflow will return to look for ovrflow for answers. Then it will look to ovrflow for answers. ovrflow will tell it to look to ovrflow for answers. Now just repeat that for a while and you got a stack overflow.int ovrflow() { return ovrflow(); }
What the picture means is that the function would have to be so large to calculate your mother's weight, that it would cause so many big numbers that it will take up so much memory that it will go excessively deep into the function, and return a stack overflow.
Sponge wrote:Correct me if I'm wrong, a stack overflow is when a stack is taking up way too much memory. For example:You're right, but that code is likely to be optimised into a tailcall, which will not chew your stack.Code: Select allint ovrflow() { return ovrflow(); }
ovrflow:
call ovrflow
ret
ovrflow:
jmp ovrflow
int fac(int n)
{
return (n <= 1
? 1
: n * fac(n-1));
}
fac:
mov eax,[esp+4]
cmp eax,1
jg .cont
mov eax,1
ret 4
.cont:
mov ecx, eax
dec ecx
push ecx
call fac
mul eax, eax, ecx
ret 4
int fac_part(int n, int s)
{
return (n <= 1
? s
: fac_part(n-1, s*n));
}
int fac(int n)
{
return fac_part(n, 1);
}
fac_part:
mov eax,[esp+8] ; eax <- s
mov ecx,[esp+4] ; ecx <- n
cmp ecx, 1
jg .cont
ret 8
.cont:
mul eax, eax, ecx
dec ecx
mov [esp+8],eax
mov [esp+4],ecx
jmp fac_part
fac:
mov eax,[esp+4]
push dword 1
push eax
call fac_part
ret 4
Users browsing this forum: No registered users and 2 guests