代码示例:1.2.1 C 程序结构与标准演进
全部示例均标注编译命令、适用环境与实测状态;完整验证记录见《03.5-代码编译运行验证记录》。
examples/ex1-c99-features.c · C99+ 常用写法(// 注释 / for 循环内声明 / stdint.h / _Bool)
/* ex1-c99-features.c —— C99+ 常用写法演示(1.2.1 ex1) * 适用环境:Linux / Windows(MinGW) 标准:C11(纯标准,无 GNU 扩展) * 编译:gcc ex1-c99-features.c -o ex1 -std=c11 -Wall -Wextra -Wpedantic * 运行:Linux: ./ex1 Windows: ex1.exe * 演示:// 注释、for 循环内声明、stdint.h 固定宽度类型、_Bool */ #include <stdio.h> #include <stdint.h> #include <stdbool.h> int main(void) { int64_t total = 0; /* stdint.h:固定宽度类型 */ for (int i = 1; i <= 5; i++) { /* C99:循环内声明变量 */ total += i; } bool done = (total == 15); /* stdbool.h:_Bool 别名 */ printf("total = %lld, done = %s\n", (long long)total, done ? "true" : "false"); return 0; }