You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何GCC 9.3.0仍未实现gets_s()?开启-std=c11编译选项仍无效

Why isn't gets_s() implemented in GCC 9.3.0 even with -std=c11?

Great question—this boils down to how C standards handle optional features and the design priorities of the GNU C Library (glibc), which GCC depends on for standard library functionality. Let’s break it down clearly:

  • gets_s() belongs to an optional C11 annex
    The gets_s() function is part of C11's Annex K, which defines "Bounds-checking interfaces". Unlike core standard functions that every conforming implementation must support, Annex K functions are explicitly marked as optional. The C standard doesn’t mandate compilers or libraries to include these functions, so many implementations (including glibc) choose not to.

  • Glibc’s position on Annex K
    The glibc maintainers have publicly criticized Annex K’s design, citing issues like inflexible interfaces, unnecessary compatibility breaks with existing code, and the fact that widely adopted safer alternatives (like fgets(), which you mentioned) already solve the problem of unsafe input. For these reasons, glibc has never implemented any Annex K functions—including gets_s()—even in versions that fully support C11.

  • Practical alternatives for your code
    If you need bounds-checked string input, stick with fgets(): it’s portable across all standard-compliant C implementations and eliminates the critical security flaws of the old gets() function (which is now completely removed from the C standard). If you specifically require behavior matching gets_s(), you’d need to use a compiler/library that implements Annex K (like Microsoft Visual C++) or build a simple wrapper around fgets() to replicate its behavior.

内容的提问来源于stack exchange,提问作者brushmonk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 15:32:37