B
bitshadow
using the following code, i was able to have my compiler seg fault on
me when i gave the argument as anythng greater than 20,832,000bytes. In
the case of the struct its 868 instances of said structure. The
compiler obviously allows VLA however it craps out after the above
amount of bytes.
I was told i was attempting to put everythng on the stack and not the
heap. So i was wondering if anyone can maybe clear it up, is that true?
would i have to then malloc 868 instances of that struct when needed to
avoid a seg fault? what exactly is the stack and the heap, i've never
really gotten around to that yet?
code:
/*program illustrates devc++ ability to create a VLA.*/
#include<stdio.h>
#include<string.h>
#define SIZE 200
#define MAX_CLMS 12
typedef struct{
char info[SIZE];
}CLMS
typedef struct{
CLMS clm[MAX_CLMS];
}PERSON;
int main(){
printf("how many arrays?");
int num;int n=0;
scanf("%d", &num);
PERSON array[num];
int x[num];
for(n=0;n<num;n++)
x[n]=n;
for(n=0;n<num;n++)
printf("%d\n",x[n]);
main(); /*for testing purposes*/
getchar();getchar();
return 0;
}
me when i gave the argument as anythng greater than 20,832,000bytes. In
the case of the struct its 868 instances of said structure. The
compiler obviously allows VLA however it craps out after the above
amount of bytes.
I was told i was attempting to put everythng on the stack and not the
heap. So i was wondering if anyone can maybe clear it up, is that true?
would i have to then malloc 868 instances of that struct when needed to
avoid a seg fault? what exactly is the stack and the heap, i've never
really gotten around to that yet?
code:
/*program illustrates devc++ ability to create a VLA.*/
#include<stdio.h>
#include<string.h>
#define SIZE 200
#define MAX_CLMS 12
typedef struct{
char info[SIZE];
}CLMS
typedef struct{
CLMS clm[MAX_CLMS];
}PERSON;
int main(){
printf("how many arrays?");
int num;int n=0;
scanf("%d", &num);
PERSON array[num];
int x[num];
for(n=0;n<num;n++)
x[n]=n;
for(n=0;n<num;n++)
printf("%d\n",x[n]);
main(); /*for testing purposes*/
getchar();getchar();
return 0;
}