I'm trying to allocate a variable-sized array on stack. The program compiles with c99 option, but it generates segmentation fault. My debugger showed that no value can be assigned to the array im1.
int main()
{
FILE * file = fopen("./image.jpg", "rb");
fseek(file, 0, SEEK_END);
const long len = ftell(file);
uint8_t im1[len];
for(int i=0;i<len;i++){
im1[i] = 0;
}
I'm programming on MacOS and use lldb for debugging. The image.jpg size is 14MB. The setting function with for loop does not work. Can someone please explain why it happens?
If possible, I want to allocate the array not on heap but on stack to maximize computing speed.