【问题标题】:xy::isfinite compiles on Linux, BSD, and Windows, but not SmartOSxy::isfinite 可在 Linux、BSD 和 Windows 上编译,但不能在 SmartOS 上编译
【发布时间】:2021-01-17 09:48:53
【问题描述】:

我正在尝试将Quadlods 移植到 SmartOS。它在 Linux 和 DragonFly BSD 上编译和运行。我还没有尝试在 Windows 上运行它,但是使用 xy 类和 isfinite 方法的其他程序可以在 Windows 上编译和运行。但是,在 SmartOS 上编译它,我得到了这个错误:

[ 15%] Building CXX object CMakeFiles/quadlods.dir/filltest.cpp.o
In file included from /usr/include/math.h:36,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/std_abs.h:40,
                 from /opt/local/gcc9/include/c++/9.3.0/cstdlib:77,
                 from /opt/local/gcc9/include/c++/9.3.0/ext/string_conversions.h:41,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/basic_string.h:6493,
                 from /opt/local/gcc9/include/c++/9.3.0/string:55,
                 from /opt/local/gcc9/include/c++/9.3.0/stdexcept:39,
                 from /opt/local/gcc9/include/c++/9.3.0/optional:38,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/node_handle.h:39,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/stl_tree.h:72,
                 from /opt/local/gcc9/include/c++/9.3.0/map:60,
                 from /home/phma/src/quadlods/quadlods.h:27,
                 from /home/phma/src/quadlods/filltest.h:25,
                 from /home/phma/src/quadlods/filltest.cpp:26:
/home/phma/src/quadlods/xy.h:35:8: error: expected ')' before '!=' token
   35 |   bool isfinite() const;
      |        ^~~~~~~~

定义宏的文件,导致这个奇怪的错误,是/usr/include/iso/math_c99.h:

#define isfinite(x) (__builtin_isfinite(x) != 0)

头文件中的类定义是

class xy
{
public:
  xy(double e,double n);
  xy();
  double getx() const;
  double gety() const;
  double length() const;
  bool isfinite() const;
  bool isnan() const;
  friend xy operator+(const xy &l,const xy &r);
  friend xy operator+=(xy &l,const xy &r);
  friend xy operator-=(xy &l,const xy &r);
  friend xy operator-(const xy &l,const xy &r);
  friend xy operator-(const xy &r);
  friend xy operator*(const xy &l,double r);
  friend xy operator*(double l,const xy &r);
  friend xy operator/(const xy &l,double r);
  friend xy operator/=(xy &l,double r);
  friend bool operator!=(const xy &l,const xy &r);
  friend bool operator==(const xy &l,const xy &r);
  friend xy turn90(xy a);
  friend xy turn(xy a,int angle);
  friend double dist(xy a,xy b);
protected:
  double x,y;
};

是否可以在不重命名方法的情况下在 SmartOS 上进行编译?我想过取消定义 isfinite 宏,但是在另一个程序(不是 Quadlods,其头文件只有 quadlods.h)中,xy 类位于库的头文件中。此外,isfinite 方法调用 std::isfinite。

【问题讨论】:

  • 欢迎来到宏的美妙世界。这种问题正是宏通常不被鼓励的确切原因。

标签: c++ macros smartos


【解决方案1】:

Jonathan Perkin 在 IRC 上给我的解决方案是将 #include <cmath> 放在 xy.h 的包含保护之后。这将取消定义宏。它现在可以在 Linux、BSD 和 SmartOS 上编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多