本文介绍了为什么GCC允许在C ++中使用round(),即使使用ansi和pedantic标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使使用 -ansi -pedantic 标志,这个程序在GCC下编译的原因是什么?

Is there a good reason why this program compiles under GCC even with the -ansi and -pedantic flags?

#include <cmath>

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

     return static_cast<int>(round(x));
}

这会使用 g ++ -ansi -pedantic -Wall test.cpp -o test

我看到两个问题:


  1. round() li>
  2. 即使 round()在这种情况下可用,但应该只能从 std 命名空间

  1. round() shouldn't be available to C++ in ISO-conformant mode (since it comes from C99)
  2. Even if round() were available in this case, it should only be so from the std namespace

我错了吗?

推荐答案

。它已经在一个惊人的长期。显然,还没有足够的集体愿望来解决它。有了一个新版本的C ++就在角落里,它将采用math.h的C99函数,它似乎不太可能被修复。

This is a bug. It's been around for a surprisingly long while. Apparently, there has not been enough of a collective desire to fix it. With a new version of C++ just around the corner which will adopt the C99 functions from math.h, it seems unlikely it will ever be fixed.

这篇关于为什么GCC允许在C ++中使用round(),即使使用ansi和pedantic标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 11:59