#include <stdio.h>
#include <string.h>
int main(void) {
char out[64];
int len = snprintf(out, sizeof(out), "Hello, World! \n");
int c1_pass = (len == 15 && strcmp(out, "Hello, World! \n") == 0);
long stdc_ver = __STDC_VERSION__;
int ptr_bytes = (int)sizeof(void *);
int c2_pass = (stdc_ver == 201112L && ptr_bytes == 8);
const char *path = "/tmp/vscode_test.c";
const char *src = "#include <stdio.h>\nint main(void) {\n printf(\"Hello, World! \\n\");\n return 0;\n}\n";
FILE *fw = fopen(path, "wb");
size_t wn = 0;
if (fw) {
wn = fwrite(src, 1, strlen(src), fw);
fclose(fw);
}
char rbuf[256] = "";
FILE *fr = fopen(path, "rb");
size_t rn = 0;
if (fr) {
rn = fread(rbuf, 1, sizeof(rbuf) - 1, fr);
rbuf[rn] = '\0';
fclose(fr);
}
remove(path);
int c3_pass = (wn == strlen(src) && rn == wn && strcmp(rbuf, src) == 0);
printf("{\"runtime\": \"GCC C11 (mstorsjo/llvm-mingw:20260616)\", \"cases\": [\n");
printf(" {\"name\": \"test_c_hello_output\", \"expected\": {\"len\": 15, \"matched\": true}, \"actual\": {\"len\": %d, \"matched\": %s}, \"passed\": %s},\n",
len, c1_pass ? "true" : "false", c1_pass ? "true" : "false");
printf(" {\"name\": \"compiler_diagnostics_and_c11\", \"expected\": {\"stdc_version\": 201112, \"ptr_bytes\": 8}, \"actual\": {\"stdc_version\": %ld, \"ptr_bytes\": %d}, \"passed\": %s},\n",
stdc_ver, ptr_bytes, c2_pass ? "true" : "false");
printf(" {\"name\": \"terminal_build_file_check\", \"expected\": {\"bytes\": %zu, \"matched\": true}, \"actual\": {\"bytes\": %zu, \"matched\": %s}, \"passed\": %s}\n",
strlen(src), rn, (strcmp(rbuf, src) == 0) ? "true" : "false", c3_pass ? "true" : "false");
printf("]}\n");
return 0;
}
本例需在 本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC 13.3.0 C11 linux/amd64,--network none)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC 13.3.0 C11 linux/amd64,--network none)。
入口文件:projects/c-vscode-lab/explore-vscode.c
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-vscode.c,或下载右侧课程工程包。 - 确认本地已准备 本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC 13.3.0 C11 linux/amd64,--network none)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联63章) · 含当前章节或实例 · mbskycom202612a3210.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3271.zip