Re: why does this work ?
From: Sidney Cadot (sidney_at_jigsaw.nl)
Date: 10/11/03
- Next message: Serve La: "Re: The '_' char in variable names"
- Previous message: Sidney Cadot: "Re: why still use C?"
- In reply to: Joona I Palaste: "Re: why does this work ?"
- Next in thread: Christian Bau: "Re: why does this work ?"
- Reply: Christian Bau: "Re: why does this work ?"
- Reply: Chris Torek: "Re: why does this work ?"
- Reply: Barry Schwarz: "Re: why does this work ?"
- Reply: Mark McIntyre: "Re: why does this work ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 11 Oct 2003 12:53:07 +0200
Joona I Palaste wrote:
> <snip>
> There is no requirement for implementations to *have* a stack in the first place.
This is the second time I see this posted over the last couple of days,
and you're surely right. But it does beg the following question:
----
#include <stdio.h>
/* returns n! modulo 2^(number of bits in an unsigned long) */
unsigned long f(unsigned long n)
{
return (n==0) ? 1 : f(n-1)*n;
}
int main(void)
{
unsigned long z;
for(z=1;z!=0;z*=2)
{
printf("%lu %lu\n", z, f(z));
fflush(stdout);
}
return 0;
}
----
As far as I can see, this is a perfectly valid C program that should
reach the 'return 0' statement always, were it not for the fact that in
all compilers I tried (one, actually) it terminates with a segmentation
fault of some sort, due to limited stack size.
Is this 'incorrect behavior' of all these compilers, or is there some
wording in the Standard that covers for machines with a finite stack
(much to my dismay, this covers all machines I have access to)?
If so, is there a minimum depth of function calls that I can rely on to
be executed properly? I would hate to rewrite all my programs to do
everything within main() without function calls, for the ultimate
portability :-)
Best regards,
Sidney
- Next message: Serve La: "Re: The '_' char in variable names"
- Previous message: Sidney Cadot: "Re: why still use C?"
- In reply to: Joona I Palaste: "Re: why does this work ?"
- Next in thread: Christian Bau: "Re: why does this work ?"
- Reply: Christian Bau: "Re: why does this work ?"
- Reply: Chris Torek: "Re: why does this work ?"
- Reply: Barry Schwarz: "Re: why does this work ?"
- Reply: Mark McIntyre: "Re: why does this work ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|