Re: int main(void) { return main(); }
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Sat, 31 Mar 2007 17:40:24 +0000
Daniel Rudy said:
At about the time of 3/29/2007 10:52 PM, JimS stated the following:
On Fri, 30 Mar 2007 04:18:34 GMT, Daniel Rudy <spamthis@xxxxxxxxxxxx>
wrote:
The program that you gave:
int main(void) { return main(); }
is an infinite recursive loop. It will run until the stack blows
up.
Which is what happened in my case. As to why you got a return
value, that's implementation specific: aka undefined behavior.
What's a stack? Where's that in the C standard?
Jim
It's not, but judging from the computers in use today, it's a
reasonable
assumption. As for your first question, you are joking, right?
Here's a stack:
void push(unsigned char c); /* stick this in a header */
unsigned char pop(void); /* and this */
static unsigned char stack[6] = {0};
static unsigned int stackptr = 0;
void push(unsigned char c)
{
if(stackptr < 6)
{
char[stackptr++] = c;
}
}
unsigned char pop(void)
{
unsigned char c = 0;
if(stackptr > 0)
{
c = char[--stackptr];
}
return c;
}
I don't quite see what this has to do with recursive functions.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- References:
- int main(void) { return main(); }
- From: Army1987
- Re: int main(void) { return main(); }
- From: Daniel Rudy
- Re: int main(void) { return main(); }
- From: JimS
- Re: int main(void) { return main(); }
- From: Daniel Rudy
- int main(void) { return main(); }
- Prev by Date: Re: how to quit
- Next by Date: Re: [OT] Re: Etymology of "struct"
- Previous by thread: Re: int main(void) { return main(); }
- Next by thread: Re: int main(void) { return main(); }
- Index(es):
Relevant Pages
|