cmath vs math.h(以及类似的c前缀vs .h扩展头) [英] cmath vs math.h (And similar c-prefixed vs .h extension headers)

查看:442
本文介绍了cmath vs math.h(以及类似的c前缀vs .h扩展头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到一些有关 iostream iostream.h 之间差异的信息。从我那里收集到的信息之间的区别是,没有扩展名 .h 的版本将不会填充名称空间,而扩展名的版本将不会填充命名空间。

I've seen some information about differences between things like iostream vs iostream.h. From what I gathered from those the difference between them is that the version without the .h extension will not populate the namespace while the version with the extension will.

cmath math.h 是否相同?为什么 cmath (以及许多其他类似文件)的前缀是 c 而不是数学?它们之间还有更多区别吗?

Is this the same for cmath vs math.h? Why is cmath (and many other files like it) prefixed with a c instead of just being math? Are there more differences between them?

推荐答案


我已经看到了一些类似东西之间差异的信息iostream vs iostream.h。

I've seen some information about differences between things like iostream vs iostream.h.

[iostream.h]不是标准标头。

[iostream.h] is not a standard header.

这不是您提出的问题的示例。

it is not an example of the issue you're raising.

[cmath]在 std 名称空间,也可以在全局名称空间中定义符号。 [math.h]在全局命名空间中定义符号,也可以在 std 命名空间中定义符号。如果包含前者并使用不合格的符号,则它可以使用一个编译器编译,而不能使用另一个编译器编译。因此,最好使用[math.h]。

[cmath] defines symbols in the std namespace, and may also define symbols in the global namespace. [math.h] defines symbols in the global namespace, and may also define symbols in the std namespace. if you include the former and use an unqualified symbol, it may compile with one compiler but not with another. therefore it's a good idea to use [math.h]. and in general, for such header pairs, to use the [.h] version.

c ++ 98提供了c 的正式保证。 xxx 标头不污染全局名称空间。也许这就是为什么要对其进行定义。但是,它的实现比污染的实现难一些,因此在实践中,我所知道的标准库实现在这方面都没有遵循该标准,因此最终更改为反映c ++ 11中的现实。

c++98 provided a formal guarantee of the cxxx header not polluting the global namespace. maybe that was why they were defined. however, that was a bit harder to implement than polluting ones, so in practice no standard library implementation that i know of followed the standard in this respect, and so it was finally changed to reflect reality in c++11.

这篇关于cmath vs math.h(以及类似的c前缀vs .h扩展头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆