#include <stdio.h>
#include <stdbool.h>
int main(void) {
bool is_ready = true;
bool is_finished = false;
int defined_flag = __bool_true_false_are_defined;
int same_size = (sizeof(bool) == sizeof(_Bool)) ? 1 : 0;
bool c1_pass = (is_ready == 1 && is_finished == 0 && defined_flag == 1 && same_size == 1);
bool b_pos = 42;
bool b_neg = -7;
bool b_zero = 0;
double frac = 0.25;
bool b_frac = frac;
bool c2_pass = ((int)b_pos == 1 && (int)b_neg == 1 && (int)b_zero == 0 && (int)b_frac == 1);
bool condition = false;
int iterations = 0;
while (!condition) {
iterations++;
condition = true;
}
bool logged_in = false;
if (!logged_in) {
logged_in = true;
}
bool c3_pass = (iterations == 1 && condition == true && logged_in == true && (!is_finished && is_ready));
printf(
"{"
"\"runtime\":\"GCC C11 (mstorsjo/llvm-mingw:20260616)\","
"\"cases\":["
"{\"name\":\"bool_macros_and_values\",\"expected\":\"t=1,f=0,def=1,sz=1\",\"actual\":\"t=%d,f=%d,def=%d,sz=%d\",\"passed\":%s},"
"{\"name\":\"bool_normalization_semantics\",\"expected\":\"pos=1,neg=1,zero=0,frac=1\",\"actual\":\"pos=%d,neg=%d,zero=%d,frac=%d\",\"passed\":%s},"
"{\"name\":\"control_flow_and_logical_ops\",\"expected\":\"iter=1,cond=1,login=1\",\"actual\":\"iter=%d,cond=%d,login=%d\",\"passed\":%s}"
"]"
"}\n",
(int)is_ready, (int)is_finished, defined_flag, same_size, c1_pass ? "true" : "false",
(int)b_pos, (int)b_neg, (int)b_zero, (int)b_frac, c2_pass ? "true" : "false",
iterations, (int)condition, (int)logged_in, c3_pass ? "true" : "false"
);
return 0;
}
本例需在 本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC C11 linux/amd64,--network none)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC C11 linux/amd64,--network none)。
入口文件:projects/c-standard-library-stdbool-h-lab/explore-standard-library-stdbool-h.c
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-standard-library-stdbool-h.c,或下载右侧课程工程包。 - 确认本地已准备 本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC C11 linux/amd64,--network none)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3253.zip
课程关联工程包(登记关联63章) · 含当前章节或实例 · mbskycom202612a3210.zip