What I'm trying to do:
I need to write integers into a 2d array. The length of the array is N*N. So I scanf to get the value of N from the user.
The C/C++ extension gives the "expression must have a constant value". But building it with gcc works perfectly fine
What I've tried:
C/C++ extension gives error on N
in both arrays, "expression must have a constant value".
After some googling answers, I tried to set my compiler version in the extension to c99, since that is the version which supports variable length arrays. But it still give the same error. Tried using other newer c versions, the intellicense still gives the same error.
Code and settings:
tree.c:
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, i, j;
scanf("%d", &N);
int min_tree[N][N];
int tree_walked[N];
}
c_cpp_properties.json:
{
"name": "TUF_Laptop",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include",
"/usr/include",
"/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include",
"/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include-fixed",
"/usr/lib/gcc/x86_64-pc-linux-gnu"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "/usr/bin/gcc",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-O3 -Wall -Wextra -std=c99"
],
"cStandard": "c99",
"cppStandard": "gnu++17",
"compileCommands": ""
}
Similar answers I found: "expression must have a constant value" error in VS code for C