跳转到正文

C99:现代 C 的重要扩展 ​

C99 对语言表达力和数值计算能力进行了大幅扩展,是很多现代 C 代码风格的起点。

参考官方标准:WG14 N1256:C99 与三次技术勘误的合并草案

代表变化 ​

  • 允许声明与语句混合,并可在 for 初始化部分声明变量。
  • 增加 // 单行注释。
  • 增加指定初始化器和复合字面量。
  • 增加 inline、restrict、long long 与 _Bool。
  • 增加变长数组和柔性数组成员。
  • 标准库增加 <stdint.h>、<stdbool.h> 与复数支持。

指定初始化与复合字面量 ​

c
#include <stdio.h>

typedef struct {
    const char *host;
    int port;
    int timeout_seconds;
} Config;

static void print_config(Config config) {
    printf("%s:%d timeout=%d\n",
           config.host,
           config.port,
           config.timeout_seconds);
}

int main(void) {
    Config config = {
        .host = "localhost",
        .port = 8080,
        .timeout_seconds = 30
    };

    print_config((Config){ .host = "127.0.0.1", .port = 9000 });
    return 0;
}

指定初始化器减少了对成员顺序的依赖;未显式指定的成员会按规则初始化为零值。

固定宽度整数 ​

c
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main(void) {
    uint32_t packet_id = UINT32_C(42);
    printf("packet=%" PRIu32 "\n", packet_id);
    return 0;
}

<stdint.h> 为协议、文件格式和硬件寄存器等场景提供了更明确的整数宽度接口,但具体的精确宽度类型只在实现能够提供时存在。

下一版:C11。

版本信息与迁移 ​

  • 发布时间 / 标准时间: 1999 年
  • 维护状态: 截至 2026-08-27,以页面所链接的官方生命周期或规范状态为准
  • 运行时或平台基线: 编译器对目标 ISO C/C++ 标准及所用标准库的实现支持

迁移影响: 升级构建标准前,必须在全部目标编译器上开启对应 -std= 选项,处理被收紧或删除的语法、标准库差异和 ABI 边界,并保留旧工具链回归构建。

版本确认 ​

bash
gcc --version
clang --version

资料核对日期:2026-08-27。

Released under the MIT License.