yohhoyの日記

技術的メモをしていきたい日記

C標準ヘッダ in 未来のC++

プログラミング言語C++標準規格におけるC標準ヘッダ(<stdlib.h> や <stdio.h> など)の扱いについて。

現行C++14および次期C++1z(C++17)*1では廃止予定(deprecated)とされているが、将来のC++2a(C++20)標準に向けて廃止予定を取り止める(undeprecating)よう提言されている。P0169R0, D.5 C standard library headers [depr.c.headers]より引用。

The basic C library headers are an essential compatibility feature, and not going anywhere anytime soon. However, there are certain C++ specific counterparts that do not bring value, particularly where the corresponding C header's job is to supply macros that masquerade as keywords already present in the C++ language.

One possibility to be more aggressive here, following the decision to not adopt all C11 headers as part of the C++ mapping to C, would be to remove those same C headers from the subset that must be shipped with a C++ compiler. This would not prevent those headers being supplied, as part of a full C implementation, but would indicate that they have no value to a C++ system.

Finally, it seems clear that the C headers will be retained essentially forever, as a vital compatibility layer with C and POSIX. It may be worth undeprecating the headers, and finding a home for them as a compatibility layer in the main standard. It is also possible that we will want to explore a different approach in the future once modules are part of C++, and the library is updated to properly take advantage of the new language feature. Therefore, we make no recommendation to undeprecate these headers for C++20, but will keep looking into this space for C++23.

strong recommendation: Undeprecate the remaining [depr.c.headers] and move it directly into 20.5.5.2 [res.on.headers].

ノート:<cstdlib> や <cstdio> といったCライブラリ機能のC++ヘッダは、正式なC++言語仕様の一部であり本記事の内容とは無関係。ただし同P0169R0 D.4でC++言語機能と衝突する互換ヘッダ(<ccomplex> や <cstdbool> など)が削除候補に挙がっている。

関連URL