为什么GCC允许在C++中使用round(),即使使用ansi和pedantic标志?

Dan*_*ing 6 c++ gcc rounding c++98

有没有一个很好的理由为什么这个程序在GCC下编译,即使使用-ansi-pedantic标志?

#include <cmath>

int main (int argc, char *argv [])
{
     double x = 0.5;

     return static_cast<int>(round(x));
}
Run Code Online (Sandbox Code Playgroud)

用它来编译干净(没有警告,甚至)g++ -ansi -pedantic -Wall test.cpp -o test.

我看到两个问题:

  1. round() 在ISO-conformant模式下不应该对C++可用(因为它来自C99)
  2. 即使round()在这种情况下可用,它也应该只是std命名空间

我错了吗?

Dan*_*ing 2

这是一个错误。它已经存在了令人惊讶的很长一段时间。显然,解决这个问题的集体意愿还不够。随着新版本的 C++ 即将采用 math.h 中的 C99 函数,它似乎不太可能被修复。