【发布时间】:2017-11-11 21:06:54
【问题描述】:
我的理解是函数std::isnan 只能从 C++11 开始使用。此外,g++ 使用 -std=gnu++98,除非明确告知不要这样做。
那么为什么会编译呢?
>> cat test.cpp
#include <cmath>
int main(int argc, char** argv)
{
return std::isnan(0);
}
>> g++ test.cpp
是否有标志可以将函数从<cmath> 中取出?
【问题讨论】:
-
可能是自 it exists in C99 以来的扩展。如果使用
-pedantic编译会发生什么? -
@NathanOliver 它仍然与
-pedantic一起编译。如果它使用 C99 宏,它不应该在全局命名空间中吗? -
这些 C 宏实际上是按照 C++ 标准 (see this answer) 作为函数实现的。有趣的是,即使在带有 -std=c++98 的 gcc 4.4.7 中,您也会在程序集中看到
__gnu_cxx::__enable_if<std::__is_arithmetic<int>::__value, int>::__type std::isnan<int>(int)。