From: Öö Tiib on
On Apr 28, 12:23 pm, boltar2...(a)boltar.world wrote:
> On Wed, 28 Apr 2010 09:21:56 +0000 (UTC)
>
> Sorry , cut and paste went wrong, that obviously should have been:
>
> int main()
> {
>         main();
>
> }

That is illegal to call main.
From: Nicolas George on
�� Tiib wrote in message
<104f9082-d221-457d-b8a9-fb7238548a12(a)b33g2000yqc.googlegroups.com>:
> That is illegal to call main.

In which section of the standard do you read that? I could not find it.
From: Öö Tiib on
On Apr 28, 12:17 pm, boltar2...(a)boltar.world wrote:
> On Wed, 28 Apr 2010 02:31:06 +0200
>
> Sjouke Burry <burrynulnulf...(a)ppllaanneett.nnll> wrote:
> >> Are you sure that the problem is the stack limit and not another form
> >> of memory corruption? What does the debugger tell you?
> >Last time I had a stack problem, I just wrote a very small
> >assembler routine, to return the value of the stackpointer.
> >That value, as the stack became full , moved to zero.
> >So if your system works likewise, use such a routine to
> >quit at the right moment, while there is still some left.
>
> Is there a way of doing that in C rather than assembler? My x86 assembler
> isn't great but I want the program to be portable anyway.

There are no way to do it in C because stack and its location, size
and direction are platform specific. There may be platform specific
libraries that have functions to do something in C. If there are none
then you may have to write it (or parts of it) in assember.

If you have implementation that should be portable and that depends on
properties of stack then you end up having that functionality
differently implemented for each plaform used. So you should perhaps
enwrap it behind common interface to keep your code readable.
From: boltar2003 on
On Wed, 28 Apr 2010 02:25:44 -0700 (PDT)
=?ISO-8859-1?Q?=D6=F6_Tiib?= <ootiib(a)hot.ee> wrote:
>On Apr 28, 12:23=A0pm, boltar2...(a)boltar.world wrote:
>> On Wed, 28 Apr 2010 09:21:56 +0000 (UTC)
>>
>> Sorry , cut and paste went wrong, that obviously should have been:
>>
>> int main()
>> {
>> =A0 =A0 =A0 =A0 main();
>>
>> }
>
>That is illegal to call main.

I don't think it is, but it doesn't matter because this crashes too:

$ cat t.c
void func()
{
func();
}


int main()
{
func();
}
$ cc t.c
$ a.out
Segmentation fault (core dumped)


From: Noob on
boltar wrote:

> Sjouke Burry wrote:
>
>> Last time I had a stack problem, I just wrote a very small
>> assembler routine, to return the value of the stack pointer.
>> That value, as the stack became full , moved to zero.
>> So if your system works likewise, use such a routine to
>> quit at the right moment, while there is still some left.
>
> Is there a way of doing that in C rather than assembler? My x86 assembler
> isn't great but I want the program to be portable anyway.

$ cat stack-pointer.s
..text
..globl _get_current_stack_pointer
_get_current_stack_pointer:
movl %esp, %eax
ret

$ cat foo.c
#include <stdio.h>
unsigned get_current_stack_pointer(void);
int foo(int n)
{
printf("sp=%x\n", get_current_stack_pointer( ));
return (n > 0) ? n+foo(n-1) : 0;
}
int main(void)
{
foo(5);
return 0;
}

$ gcc -Wall -Wextra foo.c stack-pointer.s
$ ./a.exe
sp=22ccac
sp=22cc8c
sp=22cc6c
sp=22cc4c
sp=22cc2c
sp=22cc0c
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: error
Next: Automake Conditional and ARG_VAR Question