Search code examples
cclionc99

Variable length arrays not possible w CLion and C99 Standard?


I´ve been happily coding with CLion to create a project for University whilst using C99 standard. As of today variable lengths for array declaration won`t work. Does anyone have any ideas why? Code:

int main() {
    // to allow debugging with CLION
    setbuf(stdout, 0);
    int number = 5;
    int myarray[number];
    return 0;
}

CMakeLists.txt

project(PG1 C)

set(CMAKE_C_STANDARD 99)

add_executable(PG1 main.c ...)

Error is:

C:\...\PG1\main.c(10): error C2057: Constant value required
C:\...\PG1\main.c(10): error C2466: Declaration of array with constant size 0 not possible
C:\...\PG1\main.c(10): error C2133: "myarray": unknown size
NMAKE : fatal error U1077: "C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1427~1.291\bin\Hostx86\x86\cl.exe": Return-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x86\nmake.exe"": Return-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x86\nmake.exe"": Return-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\HostX86\x86\nmake.exe"": Return-Code "0x2"
Stop.

Solution

  • CLion is using MS Visual Studio 2019 as the underlying compiler. MSVC is not a fully compliant C compiler, and in particular it does not support variable length arrays.

    You would have to use gcc or clang to get support for VLAs.