364,036 Members | 4964 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

[MinGW] Stack limit

Rafal 'Raf256' Maj
P: n/a
Rafal 'Raf256' Maj

Hi,
is this group good for questions also little compiler/platform related?

int tab[1024][1024];

program with this instruction compiled undre MinGW(DevCPP) and executed
under WinXP - crashes in this instruction. Probably due to stack overflow
error. How can I increase stack limit? Is there some universal method for
most C/C++ compilers ?

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~l-.~~~~~~~~~~~~~~~~~~~
GG-1175498 ____| ]____,
Rafal 'Raf256' Maj X-( * )
Rafal(at)Raf256(dot)com ,"----------"
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


Bertrand Mollinier Toublet
P: n/a
Bertrand Mollinier Toublet
Rafal 'Raf256' Maj wrote:
[color=blue]
> Hi,
> is this group good for questions also little compiler/platform related?
>
> int tab[1024][1024];
>
> program with this instruction compiled undre MinGW(DevCPP) and executed
> under WinXP - crashes in this instruction. Probably due to stack overflow
> error. How can I increase stack limit? Is there some universal method for
> most C/C++ compilers ?
>[/color]
One universal solution, that is also on-topic for this NG, is to respect
the maximum supported object size laid out by the C standard, which is
of 65535 (or was it 65536) bytes (with bytes to be taken in the C
meaning of 1 byte = sizeof(char)).

Admittedly, that doesn't help you too much :-)
--
Bertrand Mollinier Toublet
"Uno no se muere cuando debe, sino cuando puede"
-- Cor. Aureliano Buendia

Nov 13 '05 #2

pete
P: n/a
pete
Rafal 'Raf256' Maj wrote:[color=blue]
>
> Hi,
> is this group good for questions also little compiler/platform related?
>
> int tab[1024][1024];
>
> program with this instruction compiled undre MinGW(DevCPP) and executed
> under WinXP - crashes in this instruction. Probably due to stack overflow
> error. How can I increase stack limit? Is there some universal method for
> most C/C++ compilers ?[/color]

malloc might help do something close to what you want.

/* BEGIN new.c */

#include <stdio.h>
#include <stdlib.h>

#define A 1024
#define B 1024

int main(void)
{
int (*tab)[b];

tab = malloc(A * sizeof *tab);
if (!tab) {
fputs("It didn't work.\n", stderr);
exit(EXIT_FAILURE);
}
tab[1023][1023] = -1;
printf("%d\n", tab[1023][1023]);
free(tab);
return 0;
}

/* END new.c */

--
pete
Nov 13 '05 #3

Dan Pop
P: n/a
Dan Pop
In <Xns94118443EDB0raf256com@213.180.128.20> "Rafal 'Raf256' Maj" <spam@raf256.com> writes:

[color=blue]
>is this group good for questions also little compiler/platform related?[/color]

Nope. What's wrong with using compiler/platform related newsgroups?
[color=blue]
>int tab[1024][1024];
>
>program with this instruction compiled undre MinGW(DevCPP) and executed
>under WinXP - crashes in this instruction. Probably due to stack overflow
>error. How can I increase stack limit? Is there some universal method for
>most C/C++ compilers ?[/color]

Nope. You can try prefixing your declaration by static, so that
the array is no longer automatically allocated. Or allocate it
dynamically, with malloc and friends.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
Nov 13 '05 #4

Post your reply

Help answer this question



Didn't find the answer to your C / C++ question?

You can also browse similar questions: C / C++