gpt4 book ai didi

c++ - GCC 可以为 C++ 特性修改 C 头文件吗?

转载 作者:行者123 更新时间:2023-11-28 05:38:26 25 4
gpt4 key购买 nike

该标准在第 17.6.1.2 节第 4 段中指出:

Except as noted in Clauses [language.support] through [thread] and Annex [depr], the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library ([intro.refs]) or the C Unicode TR, as appropriate, as if by inclusion.

然后在第 18.2 节但第 2 段:

The contents are the same as the Standard C library header <stddef.h>, with the following changes:

我读这个意思是<cstddef>必须包括 <stddef.h>未修改。但是 GCC 在他们的头文件中有这个:

/usr/lib/gcc/$TRIPLET/5.3.1/include/stddef.h

#if defined (_STDDEF_H) || defined (__need_NULL)                                                              
#undef NULL /* in case <stdio.h> has defined it. */
#ifdef __GNUG__
#define NULL __null
#else /* G++ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else /* C++ */
#define NULL 0
#endif /* C++ */
#endif /* G++ */
#endif /* NULL not defined and <stddef.h> or need NULL. */
#undef __need_NULL

这符合标准吗?

最佳答案

你引用的关键部分是:

...the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library ([intro.refs]) or the C Unicode TR...

它在几个方面是模棱两可的:

  • 什么构成“内容”?是所有文本文件内容,还是其中的声明和定义集,还是仅对特定语言可能可见的内容(假设 C 程序未定义 __cplusplus)?

  • “as specified”是对cname的内容的要求,还是对name.h的内容的要求?如果要求涉及cname(我的解释),那么就没有与name.h内容相关的限制。

鉴于如此模棱两可,我认为您的问题没有明确的答案,但我也看不出有什么理由去关心....

关于c++ - GCC 可以为 C++ 特性修改 C 头文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37715537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com