当包含不同的标头时,C 实现可以隐式包含标准标头吗?

发布于 2024-11-24 00:57:40 字数 352 浏览 4 评论 0原文

在阅读 这是正确的 C 声明吗?如果是这样,为什么不起作用?我在想

#include <stdio.h>

int main(void) {
  int bool = 0;
  return bool == 0;
}

这个程序是否严格符合要求?换句话说,是允许stdio.h包含stdbool.h还是禁止这样做?这是规范指定的吗?

While reading Is this proper C declaration? If so, why does it not work? I was thinking about

#include <stdio.h>

int main(void) {
  int bool = 0;
  return bool == 0;
}

Is this program strictly conforming? In other words, is stdio.h allowed to include stdbool.h or is it forbidden to do so? Is this specified by the spec?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南巷近海 2024-12-01 00:57:40

C 标准头文件不能包含其他头文件。这与 C++ 不同,C++ 中明确允许这样做。

C99 标准,第 7.1.3 节

每个标头声明或定义其关联子条款中列出的所有标识符[...]
没有保留其他标识符。

C standard headers can not include other headers. This is different from C++, where it is explicitly allowed.

C99 standard, section 7.1.3

Each header declares or defines all identifiers listed in its associated subclause[...]
No other identifiers are reserved.

萌化 2024-12-01 00:57:40

我不确定它是否具有任何权威性,但这就是 Plauger说(当然这是针对 c89 的)。

标准 C 库提供了 15 个标准头文件。标头
有几个属性

它们是相互独立的。没有标准标头要求
首先包含另一个标准标头才能正常工作。
任何标准标头也不包含另一个标准标头

我在 c99 或 c89 中找不到任何提及这一点。

编辑

我可以看到inttypes.h包含stdint.h

7.8-1

标头 包含标头 并扩展它
以及托管实现提供的附加设施。

I'm not sure if it's authoritative in any way, but here's what Plauger says (granted it's for c89).

The Standard C library provides fifteen standard headers. The headers
have several properties

They are mutually independent. No standard header requires that
another standard header be first included for it to work properly.
Nor does any standard header include another standard header.

I can't find any mention of this in c99 or c89.

EDIT

I can see inttypes.h includes stdint.h

7.8-1

The header <inttypes.h> includes the header <stdint.h> and extends it
with additional facilities provided by hosted implementations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文