yohhoyの日記

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

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

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

2021-10-27追記:C++2b(C++23)に向けた提案 P2340R1 が採択され、全てのC標準ヘッダについて廃止予定が取り止められた。例えば<iso646.h>ヘッダは空っぽ、<complex.h>ヘッダは#include <complex>と規定される。

現行C++14および次期C++1z(C++17)*1では廃止予定(deprecated)とされているが、将来のC++2a(C++20)標準に向けて廃止予定を取り止める(undeprecating)よう提言されている。
→ 2021-03-12追記:2018年6月に採択された P0619R4 にて、C++20時点では本件に関して “対処しない” と結論づけている。

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++言語仕様の一部であり本記事の内容とは無関係。ただし同P0619R0 D.4でC++言語機能と衝突する互換ヘッダ(<ccomplex> や <cstdbool> など)が削除候補に挙がっている。
2021-03-12追記:C++20向けにP0619R4が採択され、C++17時点では存在していた互換ヘッダ <ccomplex>, <ciso646>, <cstdalign>, <cstdbool>, <ctgmath>が削除された。

関連URL