0

I either found a very weird bug, or I am doing something wrong.

I am using Visual Studio Code v1.62.3 with CMakeTools v1.9.2

Here's my project structure:

clab
│   CMakeLists.txt
│
└───src
        not_a_test.c

And contents of CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(clab)

add_executable(not_a_test src/not_a_test.c)

The kit I'm using is kit

So here's the strange part. If the contents of not_a_test.c are

#include <stdio.h> 

#define MAX_ARR_SIZE 500

int main(void) {
    int mat[MAX_ARR_SIZE][MAX_ARR_SIZE];

    printf("Hello!\n");

    return 0;
}

It runs absolutely normally. The normal run

But if I add one line

#include <stdio.h> 

#define MAX_ARR_SIZE 500

int main(void) {
    int mat[MAX_ARR_SIZE][MAX_ARR_SIZE];
    int mat2[MAX_ARR_SIZE][MAX_ARR_SIZE]; // this one

    printf("Hello!\n");

    return 0;
}

It suddenly stops working at all It stopped working

Also, when compiled via ideone / GCC v8.3 it works fine again: https://ideone.com/Vvrnnn ideone

So, what do you think happens here?

Yuki Endo
  • 192
  • 1
  • 7
  • first thing: Never call your program `test.exe`, most likely the OS has a command `test`, declare the arrays outside function, maybe your stack is not big enough – rioV8 Dec 15 '21 at 12:26
  • I don't think it affects anything at all, but if you think so, I'll rename it. – Yuki Endo Dec 15 '21 at 12:28
  • have you tried my other suggestion – rioV8 Dec 15 '21 at 12:29
  • No, because it wasn't there when I saw the comment. I'll try it now. – Yuki Endo Dec 15 '21 at 12:32
  • I never remember the exact stack sizes used by Windows or Linux but I believe it's somewhere around 1Mb. Your array blows up about that much memory, so you get a stack overflow. – Lundin Dec 15 '21 at 12:35
  • According to [this](https://learn.microsoft.com/en-us/cpp/build/reference/f-set-stack-size?view=msvc-170), MSVC defaults to a stack size of 1 MB. Use the `/F number` compiler option or the `/STACK:reserve,commit` linker option to change the stack size. – Ian Abbott Dec 15 '21 at 12:40

0 Answers0