`cosf`、`sinf` 等不在 `std` 中
`cosf`, `sinf`, etc. are not in `std`
根据此处的讨论,我已 reported a bug 致 Ubuntu 开发人员。
编译以下示例 C++ 程序时:
#include <cmath>
#include <stdio.h>
int main()
{
printf("%f\n", std::cosf(0.0f));
}
我收到以下错误消息:error: ‘cosf’ is not a member of ‘std’
包括 math.h
并使用非命名空间版本工作正常。怎么回事?
我在 Ubuntu 19.04 上使用 g++ 8.3.0-6ubuntu1。
我正在用 g++ --std=c++17 test.cpp
构建
那个版本的库(libstdc++8) is not fully conforming to C++17. The copyright notice says it was last updated in 2016. As of June 2019, the latest upstream release is bugged. It does have a #if __cplusplus > 201402L
section, but it doesn’t declare the identifiers required by C++17. There is an open bug report.
查看 Ubuntu 上的 /usr/include/c++/8/cmath
,它包括 <math.h>
,取消定义其函数的一系列宏(C 标准库要求)以访问它们的名称,导入 cos
、acos
等进入 std::
命名空间,然后将重载的 float
和 long double
重载声明为 inline
.
它从未在 std::
命名空间内声明 cosf
,尽管 C++17 says it shall. The C++11 standard says, “Names that are defined as functions in C shall be defined as functions in the C++ standard library,” and “Each name from the Standard C library declared with external linkage is reserved to the implementation for use as a name with extern "C"
linkage, both in namespace std
and in the global namespace.” However, it does not explicitly state that std::expf
et al. must be supported until P0175r1 in June 2016. 这显然是一个疏忽。
libc++ 库确实声明了它们,因此使用 clang++ -std=c++17 -stdlib=libc++
编译应该可以。
根据此处的讨论,我已 reported a bug 致 Ubuntu 开发人员。
编译以下示例 C++ 程序时:
#include <cmath>
#include <stdio.h>
int main()
{
printf("%f\n", std::cosf(0.0f));
}
我收到以下错误消息:error: ‘cosf’ is not a member of ‘std’
包括 math.h
并使用非命名空间版本工作正常。怎么回事?
我在 Ubuntu 19.04 上使用 g++ 8.3.0-6ubuntu1。
我正在用 g++ --std=c++17 test.cpp
那个版本的库(libstdc++8) is not fully conforming to C++17. The copyright notice says it was last updated in 2016. As of June 2019, the latest upstream release is bugged. It does have a #if __cplusplus > 201402L
section, but it doesn’t declare the identifiers required by C++17. There is an open bug report.
查看 Ubuntu 上的 /usr/include/c++/8/cmath
,它包括 <math.h>
,取消定义其函数的一系列宏(C 标准库要求)以访问它们的名称,导入 cos
、acos
等进入 std::
命名空间,然后将重载的 float
和 long double
重载声明为 inline
.
它从未在 std::
命名空间内声明 cosf
,尽管 C++17 says it shall. The C++11 standard says, “Names that are defined as functions in C shall be defined as functions in the C++ standard library,” and “Each name from the Standard C library declared with external linkage is reserved to the implementation for use as a name with extern "C"
linkage, both in namespace std
and in the global namespace.” However, it does not explicitly state that std::expf
et al. must be supported until P0175r1 in June 2016. 这显然是一个疏忽。
libc++ 库确实声明了它们,因此使用 clang++ -std=c++17 -stdlib=libc++
编译应该可以。