formulahendry / formulahendry/vscode-code-runner

[Bug] Can't run C99 exclusive Code

Open
#1,152 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.4k
Forks
351
PR merge metrics
No merged PRs in 30d

Description

- VS Code Version: Insiders Build v1.91
- OS Version: Windows 11
- Code Runner Version: v0.12.2

**Describe the bug**
When running this code snippet, I get an error despite the fact I changed the C standard in settings.json

Code:
```c
int const rows = 3;
int const columns = 4;
int studentGrades[rows][columns] = {{2, 3, 54, 3}, {4, 5, 6, 7}, {12, 43, 45, 3}};
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%d ", studentGrades[i][j]);
}
printf("\n");
}

```
settings.json file:
```json
"code-runner.executorMap": {
"c": "cls && cd $dir && gcc -std=c17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cls && cd $dir && g++ -std=c++23 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt && cls",

```
My compiler is windows-gcc-x64, since I've heard that the default compiler doesnt support C99 up until 2013. Also, the only way to get this running is to manually declare the elements of the multidimensional array:
```c
int const rows = 3;
int const columns = 4;
int studentGrades[rows][columns];
studentGrades[0][0] = 2;
studentGrades[0][1] = 3;
studentGrades[0][2] = 54;
studentGrades[0][3] = 3;
studentGrades[1][0] = 4;
studentGrades[1][1] = 5;
studentGrades[1][2] = 6;
studentGrades[1][3] = 7;
studentGrades[2][0] = 12;
studentGrades[2][1] = 43;
studentGrades[2][2] = 45;
studentGrades[2][3] = 3;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%d ", studentGrades[i][j]);
}
printf("\n");
}
```

**To Reproduce**
Steps to reproduce the behavior:

1. Change the executor map to what I've added in settings.json --> `-std=c17` and `std=c++23` (No issues with C++, just with C. Not entirely sure what happened here)
2. Run the code snippet

**Actual behavior**
I get an error:
```
error: variable-sized object may not be initialized except with an empty initializer
20 | int studentGrades[rows][columns] = {{2, 3, 54, 3}, {4, 5, 6, 7}, {12, 43, 45, 3}};
|
```

**Expected behavior**
Supposed to display the following matrix:
```
2 3 54 3
4 5 6 7
12 43 45 3
```
Please help me!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.