For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2006 > stack over folw exception









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author stack over folw exception
mangesh sawant

2006-03-22, 4:01 am

int k = 0 ;

int is_ok()
{
if(k == 0)
is_ok();

else
return 1;
}

above code gives stack overflow exception when executed .but function
dosen't have any local variables to push on stack . then why it is
giving stack overflow exception ?

Pascal Bourguignon

2006-03-22, 4:01 am

"mangesh sawant" <mangesh@interinfosystems.com> writes:

> int k = 0 ;
>
> int is_ok()
> {
> if(k == 0)
> is_ok();
>
> else
> return 1;
> }
>
> above code gives stack overflow exception when executed .but function
> dosen't have any local variables to push on stack . then why it is
> giving stack overflow exception ?


Because it has to push on the stack the address of the return point of
the recursive call, to let return know where to go!


--
__Pascal Bourguignon__ http://www.informatimago.com/

WARNING: This product attracts every other piece of matter in the
universe, including the products of other manufacturers, with a
force proportional to the product of the masses and inversely
proportional to the distance between them.
mangesh sawant

2006-03-22, 4:01 am


Pascal Bourguignon wrote:
> "mangesh sawant" <mangesh@interinfosystems.com> writes:
>
>
> Because it has to push on the stack the address of the return point of
> the recursive call, to let return know where to go!


>
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
>
> WARNING: This product attracts every other piece of matter in the
> universe, including the products of other manufacturers, with a
> force proportional to the product of the masses and inversely
> proportional to the distance between them.


Thanks for reply .

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com