Re: int main(void) { return main(); }



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.
.



Relevant Pages

  • Re: int main(void) { return main(); }
    ... int main ... is an infinite recursive loop. ... It will run until the stack blows up. ... Or until your patience runs out: ...
    (comp.lang.c)
  • Re: int main(void) { return main(); }
    ... int main ... is an infinite recursive loop. ... It will run until the stack blows up. ... Where's that in the C standard? ...
    (comp.lang.c)
  • [PATCH] trivial: fix typos concerning "address"
    ... struct io7 *io7; ... + * Hook the return address and push it in the stack of return address ... unsigned int flags; ...
    (Linux-Kernel)
  • Re: Having C code looking like C++ code
    ... providing an integer stack. ... | extern int push; ... | typedef struct stacktype { ... muck around inside the encapsulation to use the interface. ...
    (comp.lang.c)
  • Re: Heap stack Class questons
    ... int ct = 0; ... This is saving the old *frame pointer* on the stack ... The *frame pointer* is a fixed point by which parameters and local variables are ...
    (microsoft.public.vc.mfc)