Static memory allocation
hi
well i had tried to enquire about this problem
i was not able to find the solution. i know it workds when i declare the array globally. i know if i use malloc it will work and i am using the same in my program
but this question is again in my mind that what could be the reason that it dosent work here on my system because last time when i asked this question on some sytem it was able to run which they said that they have less emory then that of my system
my system config.: redhat linux 9.0 +512 RAM this is what my terminal displays
[ankit@Ankit fft]$ cat try2.c
#include <stdio.h>
int main()
{
double a[1450][1450];
a[1450][0]=999.999;
printf("%lf\n",a[1450][0]);
return 0;
}
[ankit@Ankit fft]$ gcc try2.c
[ankit@Ankit fft]$ ./a.out
Segmentation fault
[ankit@Ankit fft]$
i just want to know that if there is some problem related to stack how t oget rid of it
thanks
ANkit
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
On Fri, 24 Sep 2004 11:57:08 +0100 (BST), Ankit Jain <[email protected]> wrote
Quoted 1 line
hi
Hi,
Quoted 17 lines
well i had tried to enquire about this problem
i was not able to find the solution. i know it workds when i declare the array globally. i know if i use malloc it will work and i am using the same in my program
but this question is again in my mind that what could be the reason that it dosent work here on my system because last time when i asked this question on some sytem it was able to run which they said that they have less emory then that of my system
my system config.: redhat linux 9.0 +512 RAM this is what my terminal displays
Quoted 6 lines
[ankit@Ankit fft]$ cat
try2.c
#include <stdio.h>
intmain()
{
double a[1450][1450];
a[1450][0]=999.999;
You do not just have a stack problem : The upper bound is not 1450, but 1449, because the first index is 0.
So a[1449][0] has more chances to work correctly, but the problems generated by such a fault can be insidious and very difficult to discover, because the error can appear later in your program.
Quoted 18 lines
printf("%lf\n",a[1450][0]);
return 0;
}
[ankit@Ankit fft]$ gcctry2.c
[ankit@Ankit fft]$ ./a.out
Segmentation fault
[ankit@Ankit fft]$i just want to know that if there is some problem related to stack how t oget rid of it
thanks
ANkit
Quoted 5 lines
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
À+
PP
Signature · 4 lines
Groupe Morbihannais d'Utilisateurs de Logiciels Libres http://www.tuxbihan.org GPG fingerprint = 1A4F E154 3D2C A20E E4CA A543 7951 C5C2 E44A A0B5 Patrick Percot.
sorry boss but this also gives problem
[ankit@Ankit fft]$ cat try2.c
#include <stdio.h>
int main()
{
double a[1450][1450];
a[149][0]=999.999;
printf("%lf\n",a[149][0]);
return 0;
}
[ankit@Ankit fft]$ gcc try2.c
[ankit@Ankit fft]$ ./a.out
Segmentation fault
thanks
ankit
Quoted 39 lines · --- Patrick Percot
On Fri, 24 Sep 2004 11:57:08 +0100 (BST), Ankit Jain <[email protected]> wrote
Quoted 1 line
hi
Hi,
Quoted 4 lines
well i had tried to enquire about this problem
i was not able to find the solution. i know it
workds
Quoted 5 lines
when i declare the array globally. i know if i use malloc it will work and i am using the same in my program
but this question is again in my mind that what
could
Quoted 1 line
be the reason that it dosent work here on my
system
Quoted 1 line
because last time when i asked this question on
some
Quoted 6 lines
sytem it was able to run which they said that they have less emory then that of my system
my system config.: redhat linux 9.0 +512 RAM this is what my terminal displays
Quoted 6 lines
[ankit@Ankit fft]$ cat
try2.c
#include <stdio.h>
intmain()
{
double a[1450][1450];
a[1450][0]=999.999;You do not just have a stack problem : The upper bound is not 1450, but
1449, because the first index is 0.
Quoted 27 lines
So a[1449][0] has more chances to work correctly, but the problems
generated by such a fault can be insidious and
very difficult to
discover, because the error can appear later in your program.Quoted 19 lines
printf("%lf\n",a[1450][0]);
return 0;
}
[ankit@Ankit fft]$ gcctry2.c
[ankit@Ankit fft]$ ./a.out
Segmentation fault
[ankit@Ankit fft]$i just want to know that if there is some problem related to stack how t oget rid of it
thanks
ANkit
________________________________________________________________________
Quoted 5 lines
Quoted 4 lines
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Quoted 10 lines
À+
PPSignature · 6 lines
Groupe Morbihannais d'Utilisateurs de Logiciels Libres http://www.tuxbihan.org GPG fingerprint = 1A4F E154 3D2C A20E E4CA A543 7951 C5C2 E44A A0B5 Patrick Percot.
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Ankit,
It might be worth asking your friend which architecture and kernel they are using - if it's Linux then they'll have to be using something that automatically extends the stack quite a bit - or they're just very lucky (or using Windows 98).
Cheers,
Jon.
On Sat, 25 Sep 2004 10:14:01 +0100 (BST), Ankit Jain <[email protected]> wrote
Hello Ankit,
Quoted 15 lines
sorry boss but this also gives problem
[ankit@Ankit fft]$ cat
try2.c
#include <stdio.h>
intmain()
{
double a[1450][1450];
a[149][0]=999.999;
printf("%lf\n",a[149][0]);
return 0;
}
[ankit@Ankit fft]$ gcctry2.c
[ankit@Ankit fft]$ ./a.out
Segmentation fault
Sure, Claudio Bley gave you the solution (look at ulimit). I just pointed you on another potential problem in your code.
[..Zappé 94 lignes et 2428 caractères..]
À+
PP
Signature · 4 lines
Groupe Morbihannais d'Utilisateurs de Logiciels Libres http://www.tuxbihan.org GPG fingerprint = 1A4F E154 3D2C A20E E4CA A543 7951 C5C2 E44A A0B5 Patrick Percot.